Skip to content

Commit 6792668

Browse files
authored
Fix expect error when the command is not on the PATH. (#440)
1 parent 2540cb2 commit 6792668

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/exec/expect/expect.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,19 @@ func Commands(t *testing.T, exp ...*Expectation) {
6666

6767
// Create the command using the next level of middleware. (Which is
6868
// probably eventually os/exec.CommandContext().)
69-
cmd := previous(ctx, name, arg...)
69+
//
70+
// The prepending of ./ to the command name looks completely insane, but
71+
// there's a reason for it: if the name is a bare string like `docker`,
72+
// then Go will attempt to resolve it using $PATH. If the command
73+
// doesn't exist (because, say, we're running it in CI), then an error
74+
// is embedded within the *Cmd that will be returned when it is run,
75+
// even if we've subsequently rewritten the Path and Args fields to be
76+
// valid.
77+
//
78+
// Prepending ./ means that Go doesn't need to look the command up in
79+
// the $PATH and no error can be generated that way. Since we're going
80+
// to overwrite the Path momentarily anyway, that's fine.
81+
cmd := previous(ctx, "./"+name, arg...)
7082
if cmd == nil {
7183
t.Fatalf("unexpected nil *Cmd for %q with arguments %v", name, arg)
7284
}

0 commit comments

Comments
 (0)