Skip to content

Commit

Permalink
Use exec.CommandContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ravicious committed Nov 20, 2024
1 parent 2016050 commit a9f0e0e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tool/tsh/common/tsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,23 @@ func TestAlias(t *testing.T) {
//
// …plus whatever is set in the launch daemon plist under the EnvironmentVariables key.
func TestNoEnvVars(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
t.Cleanup(cancel)

testExecutable, err := os.Executable()
require.NoError(t, err)
// Execute an actual command and not jut `tsh help` which goes through a different code path.
cmd := exec.Command(testExecutable, "version", "--client")
cmd := exec.CommandContext(ctx, testExecutable, "version", "--client")
// Run the command with no env vars except tshBinMainTestEnv, otherwise the test would hang.
cmd.Env = []string{fmt.Sprintf("%s=1", tshBinMainTestEnv)}

t.Logf("running command %v", cmd)
output, err := cmd.CombinedOutput()
t.Logf("executable output: %v", string(output))
require.NoError(t, err)
// By checking the ctx error together with err, the error report will include "context deadline
// exceeded" if the command doesn't complete within the timeout. Otherwise the error would be just
// "signal: killed".
require.NoError(t, trace.NewAggregate(err, ctx.Err()))
}

func TestFailedLogin(t *testing.T) {
Expand Down

0 comments on commit a9f0e0e

Please sign in to comment.