aboutsummaryrefslogtreecommitdiff
path: root/test/utils/podmantest_test.go
blob: 26d359d383eb860699b6b4c939ff200883bbd567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package utils_test

import (
	. "github.com/containers/podman/v4/test/utils"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("PodmanTest test", func() {
	var podmanTest *FakePodmanTest

	BeforeEach(func() {
		podmanTest = FakePodmanTestCreate()
	})

	AfterEach(func() {
		FakeOutputs = make(map[string][]string)
	})

	It("Test NumberOfContainersRunning", func() {
		FakeOutputs["ps -q"] = []string{"one", "two"}
		Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
	})

	It("Test NumberOfContainers", func() {
		FakeOutputs["ps -aq"] = []string{"one", "two"}
		Expect(podmanTest.NumberOfContainers()).To(Equal(2))
	})

	It("Test NumberOfPods", func() {
		FakeOutputs["pod ps -q"] = []string{"one", "two"}
		Expect(podmanTest.NumberOfPods()).To(Equal(2))
	})

	It("Test WaitForContainer", func() {
		FakeOutputs["ps -q"] = []string{"one", "two"}
		Expect(WaitForContainer(podmanTest)).To(BeTrue())

		FakeOutputs["ps -q"] = []string{"one"}
		Expect(WaitForContainer(podmanTest)).To(BeTrue())

		FakeOutputs["ps -q"] = []string{""}
		Expect(WaitForContainer(podmanTest)).To(Not(BeTrue()))
	})

	It("Test GetContainerStatus", func() {
		FakeOutputs["ps --all --format={{.Status}}"] = []string{"Need func update"}
		Expect(podmanTest.GetContainerStatus()).To(Equal("Need func update"))
	})

	It("Test WaitContainerReady", func() {
		FakeOutputs["logs testimage"] = []string{""}
		Expect(WaitContainerReady(podmanTest, "testimage", "ready", 2, 1)).To(Not(BeTrue()))

		FakeOutputs["logs testimage"] = []string{"I am ready"}
		Expect(WaitContainerReady(podmanTest, "testimage", "am ready", 2, 1)).To(BeTrue())

		FakeOutputs["logs testimage"] = []string{"I am ready"}
		Expect(WaitContainerReady(podmanTest, "testimage", "", 2, 1)).To(BeTrue())
	})

})