fix(cmd): test workaround with panic instatt of fatal
This commit is contained in:
parent
56534a8598
commit
8886267fad
|
@ -1,8 +1,6 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/bdlm/log"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -20,7 +18,8 @@ var RootCmd = &cobra.Command{
|
|||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
if err := RootCmd.Execute(); err != nil {
|
||||
log.Fatal(err)
|
||||
os.Exit(1)
|
||||
// workaround for Fatal (os.Exit(1))
|
||||
//TODO https://github.com/stretchr/testify/issues/813
|
||||
log.Panic(err)
|
||||
}
|
||||
}
|
||||
|
|
11
main_test.go
11
main_test.go
|
@ -1,7 +1,14 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDummy(t *testing.T) {
|
||||
main()
|
||||
assert := assert.New(t)
|
||||
assert.Panics(func() {
|
||||
main()
|
||||
})
|
||||
}
|
||||
|
|
Reference in New Issue