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