github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/events_test.go (about) 1 package integration 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 "strings" 8 9 . "github.com/containers/libpod/test/utils" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("Podman events", func() { 15 var ( 16 tempdir string 17 err error 18 podmanTest *PodmanTestIntegration 19 ) 20 21 BeforeEach(func() { 22 tempdir, err = CreateTempDirInTempDir() 23 if err != nil { 24 os.Exit(1) 25 } 26 podmanTest = PodmanTestCreate(tempdir) 27 podmanTest.SeedImages() 28 }) 29 30 AfterEach(func() { 31 podmanTest.Cleanup() 32 f := CurrentGinkgoTestDescription() 33 timedResult := fmt.Sprintf("Test: %s completed in %f seconds", f.TestText, f.Duration.Seconds()) 34 GinkgoWriter.Write([]byte(timedResult)) 35 36 }) 37 38 // For most, all, of these tests we do not "live" test following a log because it may make a fragile test 39 // system more complex. Instead we run the "events" and then verify that the events are processed correctly. 40 // Perhaps a future version of this test would put events in a go func and send output back over a channel 41 // while events occur. 42 It("podman events", func() { 43 Skip("need to verify images have correct packages for journald") 44 _, ec, _ := podmanTest.RunLsContainer("") 45 Expect(ec).To(Equal(0)) 46 result := podmanTest.Podman([]string{"events", "--stream=false"}) 47 result.WaitWithDefaultTimeout() 48 Expect(result.ExitCode()).To(BeZero()) 49 }) 50 51 It("podman events with an event filter", func() { 52 Skip("need to verify images have correct packages for journald") 53 _, ec, _ := podmanTest.RunLsContainer("") 54 Expect(ec).To(Equal(0)) 55 result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "event=start"}) 56 result.WaitWithDefaultTimeout() 57 Expect(result.ExitCode()).To(Equal(0)) 58 Expect(len(result.OutputToStringArray()) >= 1) 59 }) 60 61 It("podman events with an event filter and container=cid", func() { 62 Skip("need to verify images have correct packages for journald") 63 _, ec, cid := podmanTest.RunLsContainer("") 64 Expect(ec).To(Equal(0)) 65 _, ec2, cid2 := podmanTest.RunLsContainer("") 66 Expect(ec2).To(Equal(0)) 67 result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "event=start", "--filter", fmt.Sprintf("container=%s", cid)}) 68 result.WaitWithDefaultTimeout() 69 Expect(result.ExitCode()).To(Equal(0)) 70 Expect(len(result.OutputToStringArray())).To(Equal(1)) 71 Expect(!strings.Contains(result.OutputToString(), cid2)) 72 }) 73 74 It("podman events with a type and filter container=id", func() { 75 Skip("need to verify images have correct packages for journald") 76 _, ec, cid := podmanTest.RunLsContainer("") 77 Expect(ec).To(Equal(0)) 78 result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "type=pod", "--filter", fmt.Sprintf("container=%s", cid)}) 79 result.WaitWithDefaultTimeout() 80 Expect(result.ExitCode()).To(Equal(0)) 81 Expect(len(result.OutputToStringArray())).To(Equal(0)) 82 }) 83 84 It("podman events with a type", func() { 85 Skip("need to verify images have correct packages for journald") 86 setup := podmanTest.Podman([]string{"run", "-dt", "--pod", "new:foobarpod", ALPINE, "top"}) 87 setup.WaitWithDefaultTimeout() 88 stop := podmanTest.Podman([]string{"pod", "stop", "foobarpod"}) 89 stop.WaitWithDefaultTimeout() 90 Expect(stop.ExitCode()).To(Equal(0)) 91 Expect(setup.ExitCode()).To(Equal(0)) 92 result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "type=pod", "--filter", "pod=foobarpod"}) 93 result.WaitWithDefaultTimeout() 94 Expect(result.ExitCode()).To(Equal(0)) 95 fmt.Println(result.OutputToStringArray()) 96 Expect(len(result.OutputToStringArray()) >= 2) 97 }) 98 99 It("podman events --since", func() { 100 Skip("need to verify images have correct packages for journald") 101 _, ec, _ := podmanTest.RunLsContainer("") 102 Expect(ec).To(Equal(0)) 103 result := podmanTest.Podman([]string{"events", "--stream=false", "--since", "1m"}) 104 result.WaitWithDefaultTimeout() 105 Expect(result.ExitCode()).To(BeZero()) 106 }) 107 108 It("podman events --until", func() { 109 Skip("need to verify images have correct packages for journald") 110 _, ec, _ := podmanTest.RunLsContainer("") 111 Expect(ec).To(Equal(0)) 112 test := podmanTest.Podman([]string{"events", "--help"}) 113 test.WaitWithDefaultTimeout() 114 fmt.Println(test.OutputToStringArray()) 115 result := podmanTest.Podman([]string{"events", "--stream=false", "--since", "1h"}) 116 result.WaitWithDefaultTimeout() 117 Expect(result.ExitCode()).To(BeZero()) 118 }) 119 120 It("podman events format", func() { 121 info := GetHostDistributionInfo() 122 if info.Distribution != "fedora" { 123 Skip("need to verify images have correct packages for journald") 124 } 125 _, ec, _ := podmanTest.RunLsContainer("") 126 Expect(ec).To(Equal(0)) 127 test := podmanTest.Podman([]string{"events", "--stream=false", "--format", "json"}) 128 test.WaitWithDefaultTimeout() 129 fmt.Println(test.OutputToStringArray()) 130 jsonArr := test.OutputToStringArray() 131 Expect(len(jsonArr)).To(Not(BeZero())) 132 eventsMap := make(map[string]string) 133 err := json.Unmarshal([]byte(jsonArr[0]), &eventsMap) 134 if err != nil { 135 os.Exit(1) 136 } 137 _, exist := eventsMap["Status"] 138 Expect(exist).To(BeTrue()) 139 Expect(test.ExitCode()).To(BeZero()) 140 }) 141 })