Skip to content

Commit

Permalink
add test for main ffconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Enrique Lacal <[email protected]>
  • Loading branch information
EnriqueL8 committed Sep 17, 2024
1 parent b46f518 commit 907a061
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ffconfig/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,32 @@ package main
import (
"fmt"
"os"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
)

var configPath string = "../test/data/config/firefly.core.yaml"

func TestMainFail(t *testing.T) {
// Run the crashing code when FLAG is set
if os.Getenv("FLAG") == "1" {
main()
return
}
// Run the test in a subprocess
cmd := exec.Command(os.Args[0], "-test.run=TestMainFail")
cmd.Env = append(os.Environ(), "FLAG=1")
err := cmd.Run()

// Cast the error as *exec.ExitError and compare the result
e, ok := err.(*exec.ExitError)
expectedErrorString := "exit status 1"
assert.Equal(t, true, ok)
assert.Equal(t, expectedErrorString, e.Error())
}

func TestConfigMigrateRootCmdErrorNoArgs(t *testing.T) {
rootCmd.SetArgs([]string{})
defer rootCmd.SetArgs([]string{})
Expand Down

0 comments on commit 907a061

Please sign in to comment.