Skip to content

Commit

Permalink
change: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Jan 18, 2024
1 parent e6a10eb commit 38c24f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion myexec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ func RunShell(shellString string) (exitCode int, err error) {
if !ok {
return 1, errors.Wrap(err, "get command exit code failed")
}
logger.Error("exec command failed", "exitCode", exitCode, "error", err)

// got failed command exit code
exitCode := exitErr.ExitCode()
logger.Error("exec command failed", "exitCode", exitCode, "error", err)
return exitCode, err
}

Expand Down
10 changes: 9 additions & 1 deletion myexec/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ func TestRunShell(t *testing.T) {
t.Fatalf("expected exit code 0, got %d", exitCode)
}

exitCode, err = RunShell("for i in {1..5}; do echo $i; sleep 1; done")
exitCode, err = RunShell("for i in {1..3}; do echo $i; sleep 1; done")
if err != nil {
t.Fatal(err)
}
if exitCode != 0 {
t.Fatalf("expected exit code 0, got %d", exitCode)
}

exitCode, err = RunShell("ls -l; exit 3")
if err == nil {
t.Fatal(err)
}
if exitCode != 3 {
t.Fatalf("expected exit code 3, got %d", exitCode)
}
}

0 comments on commit 38c24f7

Please sign in to comment.