Skip to content

Commit

Permalink
Add test for exit code
Browse files Browse the repository at this point in the history
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
Warashi committed Sep 30, 2024
1 parent 6e7b336 commit d10876a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/app/launcher/cmd/launcher/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package launcher

import (
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -49,3 +50,34 @@ func TestGracefulStopCommand(t *testing.T) {
})
}
}

func TestGracefulStopCommandResult(t *testing.T) {
testcases := []struct {
name string
exitCode int
assertion assert.ErrorAssertionFunc
}{
{
name: "successfully exit",
exitCode: 0,
assertion: assert.NoError,
},
{
name: "exit with an error",
exitCode: 1,
assertion: assert.Error,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
cmd, err := runBinary("sh", []string{"-c", "exit " + strconv.Itoa(tc.exitCode)})
require.NoError(t, err)
require.NotNil(t, cmd)

time.Sleep(100 * time.Millisecond) // to avoid GracefulStop executed before the command exits
tc.assertion(t, cmd.GracefulStop(time.Second))
assert.False(t, cmd.IsRunning())
})
}
}

0 comments on commit d10876a

Please sign in to comment.