summaryrefslogtreecommitdiff
path: root/test/utils/podmansession_test.go
blob: 5cfa30a533c560cb41bf66bce59011ec169353c6 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package utils_test

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

var _ = Describe("PodmanSession test", func() {
	var session *PodmanSession

	BeforeEach(func() {
		session = StartFakeCmdSession([]string{"PodmanSession", "test", "Podman Session"})
		session.WaitWithDefaultTimeout()
	})

	It("Test OutputToString", func() {
		Expect(session.OutputToString()).To(Equal("PodmanSession test Podman Session"))
	})

	It("Test OutputToStringArray", func() {
		Expect(session.OutputToStringArray()).To(Equal([]string{"PodmanSession", "test", "Podman Session"}))
	})

	It("Test ErrorToString", func() {
		Expect(session.ErrorToString()).To(Equal("PodmanSession test Podman Session"))
	})

	It("Test ErrorToStringArray", func() {
		Expect(session.ErrorToStringArray()).To(Equal([]string{"PodmanSession", "test", "Podman Session", ""}))
	})

	It("Test GrepString", func() {
		match, backStr := session.GrepString("Session")
		Expect(match).To(BeTrue())
		Expect(backStr).To(Equal([]string{"PodmanSession", "Podman Session"}))

		match, backStr = session.GrepString("I am not here")
		Expect(match).To(Not(BeTrue()))
		Expect(backStr).To(BeNil())

	})

	It("Test ErrorGrepString", func() {
		match, backStr := session.ErrorGrepString("Session")
		Expect(match).To(BeTrue())
		Expect(backStr).To(Equal([]string{"PodmanSession", "Podman Session"}))

		match, backStr = session.ErrorGrepString("I am not here")
		Expect(match).To(Not(BeTrue()))
		Expect(backStr).To(BeNil())

	})

	It("Test LineInOutputStartsWith", func() {
		Expect(session.LineInOutputStartsWith("Podman")).To(BeTrue())
		Expect(session.LineInOutputStartsWith("Session")).To(Not(BeTrue()))
	})

	It("Test LineInOutputContains", func() {
		Expect(session.LineInOutputContains("Podman")).To(BeTrue())
		Expect(session.LineInOutputContains("Session")).To(BeTrue())
		Expect(session.LineInOutputContains("I am not here")).To(Not(BeTrue()))
	})

	It("Test LineInOutputContainsTag", func() {
		session = StartFakeCmdSession([]string{"HEAD LINE", "docker.io/library/busybox   latest   e1ddd7948a1c   5 weeks ago   1.38MB"})
		session.WaitWithDefaultTimeout()
		Expect(session.LineInOutputContainsTag("docker.io/library/busybox", "latest")).To(BeTrue())
		Expect(session.LineInOutputContainsTag("busybox", "latest")).To(Not(BeTrue()))
	})

	It("Test IsJSONOutputValid", func() {
		session = StartFakeCmdSession([]string{`{"page":1,"fruits":["apple","peach","pear"]}`})
		session.WaitWithDefaultTimeout()
		Expect(session.IsJSONOutputValid()).To(BeTrue())

		session = StartFakeCmdSession([]string{"I am not JSON"})
		session.WaitWithDefaultTimeout()
		Expect(session.IsJSONOutputValid()).To(Not(BeTrue()))
	})

	It("Test WaitWithDefaultTimeout", func() {
		session = StartFakeCmdSession([]string{"sleep", "2"})
		Expect(session.ExitCode()).Should(Equal(-1))
		session.WaitWithDefaultTimeout()
		Expect(session.ExitCode()).Should(Equal(0))
	})

})