hasshelper/cmd/root_test.go
2022-10-08 00:00:53 -05:00

40 lines
906 B
Go

package cmd
import (
"os"
"os/exec"
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
func TestInitConfig(t *testing.T) {
viper.Reset()
viper.Set("deployment", "testing")
viper.Set("image_dir", "/tmp")
viper.Set("webserver_port", "8080")
initConfig()
assert.Equal(t, gitVersion, viper.GetString("version"), "config version mismatch")
}
func TestInitConfigMissingImageDir(t *testing.T) {
if os.Getenv("TEST_MISSING_INPUT") == "1" {
viper.Reset()
viper.Set("deployment", "testing")
viper.Set("version", "vTest")
viper.Set("webserver_port", "8080")
initConfig()
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestInitConfigMissingImageDir")
cmd.Env = append(os.Environ(), "TEST_MISSING_INPUT=1")
err := cmd.Run()
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
return
}
t.Fatalf("process ran with err %v, want exit status 1", err)
}