github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/test/utils/podmantest_test.go (about) 1 package utils_test 2 3 import ( 4 "os" 5 6 . "github.com/containers/podman/v2/test/utils" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("PodmanTest test", func() { 12 var podmanTest *FakePodmanTest 13 14 BeforeEach(func() { 15 podmanTest = FakePodmanTestCreate() 16 }) 17 18 AfterEach(func() { 19 FakeOutputs = make(map[string][]string) 20 }) 21 22 It("Test PodmanAsUserBase", func() { 23 FakeOutputs["check"] = []string{"check"} 24 os.Setenv("HOOK_OPTION", "hook_option") 25 env := os.Environ() 26 session := podmanTest.PodmanAsUserBase([]string{"check"}, 1000, 1000, "", env, true, false, nil) 27 os.Unsetenv("HOOK_OPTION") 28 session.WaitWithDefaultTimeout() 29 Expect(session.Command.Process).ShouldNot(BeNil()) 30 }) 31 32 It("Test NumberOfContainersRunning", func() { 33 FakeOutputs["ps -q"] = []string{"one", "two"} 34 Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2)) 35 }) 36 37 It("Test NumberOfContainers", func() { 38 FakeOutputs["ps -aq"] = []string{"one", "two"} 39 Expect(podmanTest.NumberOfContainers()).To(Equal(2)) 40 }) 41 42 It("Test NumberOfPods", func() { 43 FakeOutputs["pod ps -q"] = []string{"one", "two"} 44 Expect(podmanTest.NumberOfPods()).To(Equal(2)) 45 }) 46 47 It("Test WaitForContainer", func() { 48 FakeOutputs["ps -q"] = []string{"one", "two"} 49 Expect(WaitForContainer(podmanTest)).To(BeTrue()) 50 51 FakeOutputs["ps -q"] = []string{"one"} 52 Expect(WaitForContainer(podmanTest)).To(BeTrue()) 53 54 FakeOutputs["ps -q"] = []string{""} 55 Expect(WaitForContainer(podmanTest)).To(Not(BeTrue())) 56 }) 57 58 It("Test GetContainerStatus", func() { 59 FakeOutputs["ps --all --format={{.Status}}"] = []string{"Need func update"} 60 Expect(podmanTest.GetContainerStatus()).To(Equal("Need func update")) 61 }) 62 63 It("Test WaitContainerReady", func() { 64 FakeOutputs["logs testimage"] = []string{""} 65 Expect(WaitContainerReady(podmanTest, "testimage", "ready", 2, 1)).To(Not(BeTrue())) 66 67 FakeOutputs["logs testimage"] = []string{"I am ready"} 68 Expect(WaitContainerReady(podmanTest, "testimage", "am ready", 2, 1)).To(BeTrue()) 69 70 FakeOutputs["logs testimage"] = []string{"I am ready"} 71 Expect(WaitContainerReady(podmanTest, "testimage", "", 2, 1)).To(BeTrue()) 72 }) 73 74 })