Skip to content

Commit

Permalink
add test for exit ffconfig main
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 010b61f commit e1fb4f5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ffconfig/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ func TestConfigMigrateCmd(t *testing.T) {
assert.NoError(t, err)
}

func TestMain(t *testing.T) {
// Run the exiting code when FLAG is set
if os.Getenv("FLAG") == "0" {
rootCmd.SetArgs([]string{"migrate", "-f", configPath})
main()
return
}

// Run the test in a subprocess
cmd := exec.Command(os.Args[0], "-test.run=TestMain")
cmd.Env = append(os.Environ(), "FLAG=0")
err := cmd.Run()

// Cast the error as *exec.ExitError and compare the result
_, ok := err.(*exec.ExitError)
assert.Equal(t, false, ok)
}

func TestConfigMigrateCmdWriteOutput(t *testing.T) {
tmpDir, err := os.MkdirTemp(os.TempDir(), "out")
assert.NoError(t, err)
Expand Down

0 comments on commit e1fb4f5

Please sign in to comment.