File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ func (ws *ExecStrategy) WithStartupTimeout(startupTimeout time.Duration) *ExecSt
45
45
return ws
46
46
}
47
47
48
+ func (ws * ExecStrategy ) WithExitCode (exitCode int ) * ExecStrategy {
49
+ return ws .WithExitCodeMatcher (func (actualCode int ) bool {
50
+ return actualCode == exitCode
51
+ })
52
+ }
53
+
48
54
func (ws * ExecStrategy ) WithExitCodeMatcher (exitCodeMatcher func (exitCode int ) bool ) * ExecStrategy {
49
55
ws .ExitCodeMatcher = exitCodeMatcher
50
56
return ws
Original file line number Diff line number Diff line change @@ -156,6 +156,27 @@ func TestExecStrategyWaitUntilReady_CustomExitCode(t *testing.T) {
156
156
}
157
157
}
158
158
159
+ func TestExecStrategyWaitUntilReady_withExitCode (t * testing.T ) {
160
+ target := mockExecTarget {
161
+ exitCode : 10 ,
162
+ }
163
+ wg := wait .NewExecStrategy ([]string {"true" }).WithExitCode (10 )
164
+ // Default is 60. Let's shorten that
165
+ wg .WithStartupTimeout (time .Second * 2 )
166
+ err := wg .WaitUntilReady (context .Background (), target )
167
+ if err != nil {
168
+ t .Fatal (err )
169
+ }
170
+
171
+ // Ensure we aren't spuriously returning on any code
172
+ wg = wait .NewExecStrategy ([]string {"true" }).WithExitCode (0 )
173
+ wg .WithStartupTimeout (time .Second * 2 )
174
+ err = wg .WaitUntilReady (context .Background (), target )
175
+ if err == nil {
176
+ t .Fatalf ("Expected strategy to timeout out" )
177
+ }
178
+ }
179
+
159
180
func TestExecStrategyWaitUntilReady_CustomResponseMatcher (t * testing.T ) {
160
181
// waitForExecExitCodeResponse {
161
182
dockerReq := testcontainers.ContainerRequest {
You can’t perform that action at this time.
0 commit comments