diff --git a/cmd/installer/main.go b/cmd/installer/main.go index 3b225a4..4d39a7e 100644 --- a/cmd/installer/main.go +++ b/cmd/installer/main.go @@ -6,6 +6,10 @@ import ( "github.com/wavesoftware/serverless-installer/internal/cli" ) +var exit func(int) = func(exitcode int) { + os.Exit(exitcode) +} + func main() { - os.Exit(cli.NewRunner().Run()) + exit(cli.NewRunner().Run()) } diff --git a/cmd/installer/main_test.go b/cmd/installer/main_test.go new file mode 100644 index 0000000..00203fe --- /dev/null +++ b/cmd/installer/main_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMain(t *testing.T) { + // given + oldExit := exit + oldArgs := os.Args + defer func() { + exit = oldExit + os.Args = oldArgs + }() + exitcode := ^int(0) + exit = func(received int) { + exitcode = received + } + os.Args = []string{"cmd", "--help"} + + // when + main() + + assert.Equal(t, 0, exitcode) +}