Skip to content

reexec: test cmd.Cancel, bump minimum go version to go1.20 #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion reexec/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/moby/sys/reexec

go 1.18
go 1.20
24 changes: 10 additions & 14 deletions reexec/reexec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
},
}

Expand All @@ -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 {
Expand All @@ -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))
Expand Down