Skip to content

Commit

Permalink
Adding test to main
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Oct 4, 2019
1 parent 5723c58 commit 4f3ef98
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
28 changes: 28 additions & 0 deletions cmd/installer/main_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 4f3ef98

Please sign in to comment.