Skip to content

Commit cfc556d

Browse files
committed
Tests to error on timeout
Signed-off-by: apostasie <[email protected]>
1 parent 166b078 commit cfc556d

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

cmd/nerdctl/system/system_events_linux_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func TestEventFilters(t *testing.T) {
4242
Command: testEventFilterExecutor,
4343
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
4444
return &test.Expected{
45-
Output: test.Contains(data.Get("output")),
45+
ExitCode: test.ExitCodeTimeout,
46+
Output: test.Contains(data.Get("output")),
4647
}
4748
},
4849
Data: test.WithData("filter", "event=START").
@@ -53,7 +54,8 @@ func TestEventFilters(t *testing.T) {
5354
Command: testEventFilterExecutor,
5455
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
5556
return &test.Expected{
56-
Output: test.Contains(data.Get("output")),
57+
ExitCode: test.ExitCodeTimeout,
58+
Output: test.Contains(data.Get("output")),
5759
}
5860
},
5961
Data: test.WithData("filter", "event=start").
@@ -65,7 +67,8 @@ func TestEventFilters(t *testing.T) {
6567
Command: testEventFilterExecutor,
6668
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
6769
return &test.Expected{
68-
Output: test.Contains(data.Get("output")),
70+
ExitCode: test.ExitCodeTimeout,
71+
Output: test.Contains(data.Get("output")),
6972
}
7073
},
7174
Data: test.WithData("filter", "event=unknown").
@@ -76,7 +79,8 @@ func TestEventFilters(t *testing.T) {
7679
Command: testEventFilterExecutor,
7780
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
7881
return &test.Expected{
79-
Output: test.Contains(data.Get("output")),
82+
ExitCode: test.ExitCodeTimeout,
83+
Output: test.Contains(data.Get("output")),
8084
}
8185
},
8286
Data: test.WithData("filter", "status=start").
@@ -88,7 +92,8 @@ func TestEventFilters(t *testing.T) {
8892
Command: testEventFilterExecutor,
8993
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
9094
return &test.Expected{
91-
Output: test.Contains(data.Get("output")),
95+
ExitCode: test.ExitCodeTimeout,
96+
Output: test.Contains(data.Get("output")),
9297
}
9398
},
9499
Data: test.WithData("filter", "status=unknown").

pkg/testutil/test/command.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
const ExitCodeGenericFail = -1
3737
const ExitCodeNoCheck = -2
38+
const ExitCodeTimeout = -3
3839

3940
// GenericCommand is a concrete Command implementation
4041
type GenericCommand struct {
@@ -150,11 +151,14 @@ func (gc *GenericCommand) Run(expect *Expected) {
150151
debug := result.String() + "Env:\n" + strings.Join(env, "\n")
151152
// ExitCode goes first
152153
if expect.ExitCode == ExitCodeNoCheck { //nolint:revive
153-
// -2 means we do not care at all about exit code
154+
// ExitCodeNoCheck means we do not care at all about exit code. It can be a failure, a success, or a timeout.
154155
} else if expect.ExitCode == ExitCodeGenericFail {
155-
// -1 means any error
156+
// ExitCodeGenericFail means we expect an error (excluding timeout).
156157
assert.Assert(gc.t, result.ExitCode != 0,
157-
"Expected exit code to be different than 0\n"+debug)
158+
"Command succeeded while we were expecting an error\n"+debug)
159+
} else if result.Timeout {
160+
assert.Assert(gc.t, expect.ExitCode == ExitCodeTimeout,
161+
"Command unexpectedly timed-out\n"+debug)
158162
} else {
159163
assert.Assert(gc.t, expect.ExitCode == result.ExitCode,
160164
fmt.Sprintf("Expected exit code: %d\n", expect.ExitCode)+debug)

0 commit comments

Comments
 (0)