Skip to content

Commit 00ae824

Browse files
committed
Add CrictlExpect() to test framework
This is a generic version of the CrictlExpect* allowing tests such as Exit(0), empty stdout, specific stderr.
1 parent d1732ab commit 00ae824

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

test/framework/framework.go

+25-21
Original file line numberDiff line numberDiff line change
@@ -83,50 +83,54 @@ func lcmd(format string, args ...interface{}) *Session {
8383
return cmd("", format, args...)
8484
}
8585

86-
// Run crictl and return the resulting session
87-
func (t *TestFramework) Crictl(args string) *Session {
88-
return lcmd("crictl %s", args).Wait()
89-
}
90-
9186
// Run crictl on the specified endpoint and return the resulting session
9287
func (t *TestFramework) CrictlWithEndpoint(endpoint, args string) *Session {
9388
return lcmd("crictl --runtime-endpoint=%s %s", endpoint, args).Wait(time.Minute)
9489
}
9590

91+
// Run crictl and expect exit, expectedOut, expectedErr
92+
func (t *TestFramework) CrictlExpect(
93+
endpoint, args string, exit int, expectedOut, expectedErr string,
94+
) {
95+
// When
96+
res := t.CrictlWithEndpoint(endpoint, args)
97+
98+
// Then
99+
Expect(res).To(Exit(exit))
100+
if expectedOut == "" {
101+
Expect(string(res.Out.Contents())).To(BeEmpty())
102+
} else {
103+
Expect(res.Out).To(Say(expectedOut))
104+
}
105+
if expectedErr == "" {
106+
Expect(string(res.Err.Contents())).To(BeEmpty())
107+
} else {
108+
Expect(res.Err).To(Say(expectedErr))
109+
}
110+
}
111+
96112
// Run crictl and expect success containing the specified output
97113
func (t *TestFramework) CrictlExpectSuccess(args, expectedOut string) {
98-
t.CrictlExpectSuccessWithEndpoint("", args, expectedOut)
114+
t.CrictlExpect("", args, 0, expectedOut, "")
99115
}
100116

101117
// Run crictl and expect success containing the specified output
102118
func (t *TestFramework) CrictlExpectSuccessWithEndpoint(endpoint, args, expectedOut string) {
103-
// When
104-
res := t.CrictlWithEndpoint(endpoint, args)
105-
106-
// Then
107-
Expect(res).To(Exit(0))
108-
Expect(res.Out).To(Say(expectedOut))
109-
Expect(string(res.Err.Contents())).To(BeEmpty())
119+
t.CrictlExpect(endpoint, args, 0, expectedOut, "")
110120
}
111121

112122
// Run crictl and expect error containing the specified outputs
113123
func (t *TestFramework) CrictlExpectFailure(
114124
args string, expectedOut, expectedErr string,
115125
) {
116-
t.CrictlExpectFailureWithEndpoint("", args, expectedOut, expectedErr)
126+
t.CrictlExpect("", args, 1, expectedOut, expectedErr)
117127
}
118128

119129
// Run crictl and expect failure containing the specified output
120130
func (t *TestFramework) CrictlExpectFailureWithEndpoint(
121131
endpoint, args, expectedOut, expectedErr string,
122132
) {
123-
// When
124-
res := t.CrictlWithEndpoint(endpoint, args)
125-
126-
// Then
127-
Expect(res).To(Exit(1))
128-
Expect(res.Out).To(Say(expectedOut))
129-
Expect(res.Err).To(Say(expectedErr))
133+
t.CrictlExpect(endpoint, args, 1, expectedOut, expectedErr)
130134
}
131135

132136
func SetupCrio() string {

0 commit comments

Comments
 (0)