Skip to content

Commit 147c482

Browse files
edsantiagocevich
authored andcommitted
[v4.4.1-rhel] CI: e2e: new ginkgo matcher, ExitCleanly()
Combined test for (exitcode == 0) && (nothing on stderr). Returns more useful diagnostic messages than the default: old: Expected N to equal 0 new: Command failed with exit status N new: Unexpected warnings seen on stderr: "...." Adding fro the ExitCleanOnly function that is present in some tests that were cherry picked for this PR. Signed-off-by: Ed Santiago <santiago@redhat.com> (cherry picked from commit 6cbd17c) Signed-off-by: Tom Sweeney <tsweeney@redhat.com> (cherry picked from commit a9ac512) Signed-off-by: Chris Evich <cevich@redhat.com>
1 parent 0f34fde commit 147c482

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

test/utils/matchers.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,57 @@ func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool {
168168
return true
169169
}
170170

171+
// ExitCleanly asserts that a PodmanSession exits 0 and with no stderr
172+
func ExitCleanly() types.GomegaMatcher {
173+
return &exitCleanlyMatcher{}
174+
}
175+
176+
type exitCleanlyMatcher struct {
177+
msg string
178+
}
179+
180+
type podmanSession interface {
181+
ExitCode() int
182+
ErrorToString() string
183+
}
184+
185+
func (matcher *exitCleanlyMatcher) Match(actual interface{}) (success bool, err error) {
186+
session, ok := actual.(podmanSession)
187+
if !ok {
188+
return false, fmt.Errorf("ExitCleanly must be passed a PodmanSession; Got:\n %+v\n%q", actual, format.Object(actual, 1))
189+
}
190+
191+
exitcode := session.ExitCode()
192+
stderr := session.ErrorToString()
193+
if exitcode != 0 {
194+
matcher.msg = fmt.Sprintf("Command failed with exit status %d", exitcode)
195+
if stderr != "" {
196+
matcher.msg += ". See above for error message."
197+
}
198+
return false, nil
199+
}
200+
201+
// FIXME: #19809, "failed to connect to syslog" warnings on f38
202+
// FIXME: so, until that is fixed, don't check stderr if containerized
203+
if !Containerized() {
204+
if stderr != "" {
205+
matcher.msg = fmt.Sprintf("Unexpected warnings seen on stderr: %q", stderr)
206+
return false, nil
207+
}
208+
}
209+
210+
return true, nil
211+
}
212+
213+
func (matcher *exitCleanlyMatcher) FailureMessage(_ interface{}) (message string) {
214+
return matcher.msg
215+
}
216+
217+
func (matcher *exitCleanlyMatcher) NegatedFailureMessage(_ interface{}) (message string) {
218+
// FIXME - I see no situation in which we could ever want this?
219+
return matcher.msg + " (NOT!)"
220+
}
221+
171222
type ValidJSONMatcher struct {
172223
types.GomegaMatcher
173224
}

0 commit comments

Comments
 (0)