fix(cmd): test workaround with panic instatt of fatal

This commit is contained in:
Martin/Geno 2019-09-05 20:12:46 +02:00
parent 56534a8598
commit 8886267fad
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 12 additions and 6 deletions

View File

@ -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)
} }
} }

View File

@ -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()
})
} }