summaryrefslogtreecommitdiff
path: root/test/utils/podmansession_test.go
diff options
context:
space:
mode:
authorYiqiao Pu <ypu@redhat.com>2018-10-29 14:56:07 +0800
committerYiqiao Pu <ypu@redhat.com>2018-11-16 10:49:00 +0800
commit74bcfc2f969ad55a651c4ced257fc7c60a581966 (patch)
treee8728b12e1512de0b4a821a51e19f264505bf08d /test/utils/podmansession_test.go
parent236408bbbc14f6b637c4e9be19093d1a37b83f9c (diff)
downloadpodman-74bcfc2f969ad55a651c4ced257fc7c60a581966.tar.gz
podman-74bcfc2f969ad55a651c4ced257fc7c60a581966.tar.bz2
podman-74bcfc2f969ad55a651c4ced257fc7c60a581966.zip
Separate common used test functions and structs to test/utils
Put common used test functions and structs to a separated package. So we can use them for more testsuites. Signed-off-by: Yiqiao Pu <ypu@redhat.com>
Diffstat (limited to 'test/utils/podmansession_test.go')
-rw-r--r--test/utils/podmansession_test.go90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/utils/podmansession_test.go b/test/utils/podmansession_test.go
new file mode 100644
index 000000000..de8c20b24
--- /dev/null
+++ b/test/utils/podmansession_test.go
@@ -0,0 +1,90 @@
+package utils_test
+
+import (
+ . "github.com/containers/libpod/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.LineInOuputStartsWith("Podman")).To(BeTrue())
+ Expect(session.LineInOuputStartsWith("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))
+ })
+
+})