summaryrefslogtreecommitdiff
path: root/test/utils
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2019-10-04 10:09:24 -0700
committerJhon Honce <jhonce@redhat.com>2019-10-16 08:10:07 -0700
commit60d0be17fc55404929ad24d861f318968997458f (patch)
treee6aeecf49dd00a8e1f4a32cb3c0638b041fb0572 /test/utils
parent7825c5827e039aed6656f5df65de2262591681e6 (diff)
downloadpodman-60d0be17fc55404929ad24d861f318968997458f.tar.gz
podman-60d0be17fc55404929ad24d861f318968997458f.tar.bz2
podman-60d0be17fc55404929ad24d861f318968997458f.zip
Refactor tests when checking for error exit codes
Rather than checking for non-zero, we need to check for >0 to distinguish between timeouts and error exit codes. Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'test/utils')
-rw-r--r--test/utils/matchers.go61
-rw-r--r--test/utils/utils.go12
2 files changed, 67 insertions, 6 deletions
diff --git a/test/utils/matchers.go b/test/utils/matchers.go
new file mode 100644
index 000000000..07c1232e7
--- /dev/null
+++ b/test/utils/matchers.go
@@ -0,0 +1,61 @@
+package utils
+
+import (
+ "fmt"
+
+ "github.com/onsi/gomega/format"
+ "github.com/onsi/gomega/gexec"
+)
+
+// ExitWithError matches when assertion is > argument. Default 0
+// Modeled after the gomega Exit() matcher
+func ExitWithError(optionalExitCode ...int) *exitMatcher {
+ exitCode := 0
+ if len(optionalExitCode) > 0 {
+ exitCode = optionalExitCode[0]
+ }
+ return &exitMatcher{exitCode: exitCode}
+}
+
+type exitMatcher struct {
+ exitCode int
+ actualExitCode int
+}
+
+func (m *exitMatcher) Match(actual interface{}) (success bool, err error) {
+ exiter, ok := actual.(gexec.Exiter)
+ if !ok {
+ return false, fmt.Errorf("ExitWithError must be passed a gexec.Exiter (Missing method ExitCode() int) Got:\n#{format.Object(actual, 1)}")
+ }
+
+ m.actualExitCode = exiter.ExitCode()
+ if m.actualExitCode == -1 {
+ return false, nil
+ }
+ return m.actualExitCode > m.exitCode, nil
+}
+
+func (m *exitMatcher) FailureMessage(actual interface{}) (message string) {
+ if m.actualExitCode == -1 {
+ return "Expected process to exit. It did not."
+ }
+ return format.Message(m.actualExitCode, "to be greater than exit code:", m.exitCode)
+}
+
+func (m *exitMatcher) NegatedFailureMessage(actual interface{}) (message string) {
+ if m.actualExitCode == -1 {
+ return "you really shouldn't be able to see this!"
+ } else {
+ if m.exitCode == -1 {
+ return "Expected process not to exit. It did."
+ }
+ return format.Message(m.actualExitCode, "is less than or equal to exit code:", m.exitCode)
+ }
+}
+func (m *exitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
+ session, ok := actual.(*gexec.Session)
+ if ok {
+ return session.ExitCode() == -1
+ }
+ return true
+}
diff --git a/test/utils/utils.go b/test/utils/utils.go
index 7d373bd56..ad78d9792 100644
--- a/test/utils/utils.go
+++ b/test/utils/utils.go
@@ -268,7 +268,7 @@ func (s *PodmanSession) ErrorGrepString(term string) (bool, []string) {
return matches, greps
}
-//LineInOutputStartsWith returns true if a line in a
+// LineInOutputStartsWith returns true if a line in a
// session output starts with the supplied string
func (s *PodmanSession) LineInOuputStartsWith(term string) bool {
for _, i := range s.OutputToStringArray() {
@@ -279,7 +279,7 @@ func (s *PodmanSession) LineInOuputStartsWith(term string) bool {
return false
}
-//LineInOutputContains returns true if a line in a
+// LineInOutputContains returns true if a line in a
// session output contains the supplied string
func (s *PodmanSession) LineInOutputContains(term string) bool {
for _, i := range s.OutputToStringArray() {
@@ -290,7 +290,7 @@ func (s *PodmanSession) LineInOutputContains(term string) bool {
return false
}
-//LineInOutputContainsTag returns true if a line in the
+// LineInOutputContainsTag returns true if a line in the
// session's output contains the repo-tag pair as returned
// by podman-images(1).
func (s *PodmanSession) LineInOutputContainsTag(repo, tag string) bool {
@@ -348,7 +348,7 @@ func StringInSlice(s string, sl []string) bool {
return false
}
-//tagOutPutToMap parses each string in imagesOutput and returns
+// tagOutPutToMap parses each string in imagesOutput and returns
// a map of repo:tag pairs. Notice, the first array item will
// be skipped as it's considered to be the header.
func tagOutputToMap(imagesOutput []string) map[string]string {
@@ -371,7 +371,7 @@ func tagOutputToMap(imagesOutput []string) map[string]string {
return m
}
-//GetHostDistributionInfo returns a struct with its distribution name and version
+// GetHostDistributionInfo returns a struct with its distribution name and version
func GetHostDistributionInfo() HostOS {
f, err := os.Open(OSReleasePath)
defer f.Close()
@@ -415,7 +415,7 @@ func IsKernelNewerThan(version string) (bool, error) {
}
-//IsCommandAvaible check if command exist
+// IsCommandAvaible check if command exist
func IsCommandAvailable(command string) bool {
check := exec.Command("bash", "-c", strings.Join([]string{"command -v", command}, " "))
err := check.Run()