Skip to content

Commit f4c0392

Browse files
authored
Merge pull request #194 from thaJeztah/reexec_test_cancel
reexec: test cmd.Cancel, bump minimum go version to go1.20
2 parents 6b0a691 + d197f51 commit f4c0392

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ jobs:
2525
if: ${{ matrix.go-version == '1.18.x' }}
2626
run: |
2727
# This corresponds with the list in Makefile:1, but omits the "userns"
28-
# and "capability" modules, which require go1.21 as minimum.
29-
echo 'PACKAGES=atomicwriter mountinfo mount reexec sequential signal symlink user' >> $GITHUB_ENV
28+
# and "capability" modules, which require go1.21 as minimum, and "reexec",
29+
# which requires go1.20 in tests.
30+
echo 'PACKAGES=atomicwriter mountinfo mount sequential signal symlink user' >> $GITHUB_ENV
3031
- name: go mod tidy
3132
run: |
3233
make foreach CMD="go mod tidy"

reexec/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/moby/sys/reexec
22

3-
go 1.18
3+
go 1.20

reexec/reexec_test.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ func TestCommand(t *testing.T) {
122122
}
123123

124124
func TestCommandContext(t *testing.T) {
125+
testError := errors.New("test-error: the command was canceled")
126+
125127
tests := []struct {
126128
doc string
127129
cmdAndArgs []string
128130
cancel bool
129131
expOut string
130-
expError bool
132+
expError error
131133
}{
132134
{
133135
doc: "basename",
@@ -148,13 +150,13 @@ func TestCommandContext(t *testing.T) {
148150
doc: "context canceled",
149151
cancel: true,
150152
cmdAndArgs: []string{testReExec2},
151-
expError: true,
153+
expError: context.Canceled,
152154
},
153155
{
154156
doc: "context timeout",
155157
cmdAndArgs: []string{testReExec3},
156158
expOut: "Hello test-reexec3",
157-
expError: true,
159+
expError: testError,
158160
},
159161
}
160162

@@ -167,6 +169,9 @@ func TestCommandContext(t *testing.T) {
167169
if !reflect.DeepEqual(cmd.Args, tc.cmdAndArgs) {
168170
t.Fatalf("got %+v, want %+v", cmd.Args, tc.cmdAndArgs)
169171
}
172+
cmd.Cancel = func() error {
173+
return testError
174+
}
170175

171176
w, err := cmd.StdinPipe()
172177
if err != nil {
@@ -177,17 +182,8 @@ func TestCommandContext(t *testing.T) {
177182
cancel()
178183
}
179184
out, err := cmd.CombinedOutput()
180-
if tc.cancel {
181-
if !errors.Is(err, context.Canceled) {
182-
t.Errorf("got %[1]v (%[1]T), want %v", err, context.Canceled)
183-
}
184-
}
185-
if tc.expError {
186-
if err == nil {
187-
t.Errorf("expected error, got nil")
188-
}
189-
} else if err != nil {
190-
t.Errorf("error on re-exec cmd: %v, out: %v", err, string(out))
185+
if !errors.Is(err, tc.expError) {
186+
t.Errorf("expected %v, got: %v", tc.expError, err)
191187
}
192188

193189
actual := strings.TrimSpace(string(out))

0 commit comments

Comments
 (0)