diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78c4cd24..cf6b25d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,8 +25,9 @@ jobs: if: ${{ matrix.go-version == '1.18.x' }} run: | # This corresponds with the list in Makefile:1, but omits the "userns" - # and "capability" modules, which require go1.21 as minimum. - echo 'PACKAGES=atomicwriter mountinfo mount reexec sequential signal symlink user' >> $GITHUB_ENV + # and "capability" modules, which require go1.21 as minimum, and "reexec", + # which requires go1.20 in tests. + echo 'PACKAGES=atomicwriter mountinfo mount sequential signal symlink user' >> $GITHUB_ENV - name: go mod tidy run: | make foreach CMD="go mod tidy" diff --git a/reexec/go.mod b/reexec/go.mod index 86f11609..15e248a7 100644 --- a/reexec/go.mod +++ b/reexec/go.mod @@ -1,3 +1,3 @@ module github.com/moby/sys/reexec -go 1.18 +go 1.20 diff --git a/reexec/reexec_test.go b/reexec/reexec_test.go index 0620c370..db3067fb 100644 --- a/reexec/reexec_test.go +++ b/reexec/reexec_test.go @@ -122,12 +122,14 @@ func TestCommand(t *testing.T) { } func TestCommandContext(t *testing.T) { + testError := errors.New("test-error: the command was canceled") + tests := []struct { doc string cmdAndArgs []string cancel bool expOut string - expError bool + expError error }{ { doc: "basename", @@ -148,13 +150,13 @@ func TestCommandContext(t *testing.T) { doc: "context canceled", cancel: true, cmdAndArgs: []string{testReExec2}, - expError: true, + expError: context.Canceled, }, { doc: "context timeout", cmdAndArgs: []string{testReExec3}, expOut: "Hello test-reexec3", - expError: true, + expError: testError, }, } @@ -167,6 +169,9 @@ func TestCommandContext(t *testing.T) { if !reflect.DeepEqual(cmd.Args, tc.cmdAndArgs) { t.Fatalf("got %+v, want %+v", cmd.Args, tc.cmdAndArgs) } + cmd.Cancel = func() error { + return testError + } w, err := cmd.StdinPipe() if err != nil { @@ -177,17 +182,8 @@ func TestCommandContext(t *testing.T) { cancel() } out, err := cmd.CombinedOutput() - if tc.cancel { - if !errors.Is(err, context.Canceled) { - t.Errorf("got %[1]v (%[1]T), want %v", err, context.Canceled) - } - } - if tc.expError { - if err == nil { - t.Errorf("expected error, got nil") - } - } else if err != nil { - t.Errorf("error on re-exec cmd: %v, out: %v", err, string(out)) + if !errors.Is(err, tc.expError) { + t.Errorf("expected %v, got: %v", tc.expError, err) } actual := strings.TrimSpace(string(out))