github.com/apex/up@v1.7.1/internal/userconfig/userconfig_test.go (about) 1 package userconfig 2 3 import ( 4 "os" 5 "path/filepath" 6 "testing" 7 8 "github.com/mitchellh/go-homedir" 9 "github.com/tj/assert" 10 ) 11 12 func init() { 13 configDir = ".up-test" 14 } 15 16 func TestConfig_file(t *testing.T) { 17 t.Run("load when missing", func(t *testing.T) { 18 dir, _ := homedir.Dir() 19 os.RemoveAll(filepath.Join(dir, configDir)) 20 21 c := Config{} 22 assert.NoError(t, c.Load(), "load") 23 }) 24 25 t.Run("save", func(t *testing.T) { 26 c := Config{} 27 assert.NoError(t, c.Load(), "load") 28 assert.Equal(t, "", c.Team) 29 30 c.Team = "apex" 31 assert.NoError(t, c.Save(), "save") 32 }) 33 34 t.Run("load after save", func(t *testing.T) { 35 c := Config{} 36 assert.NoError(t, c.Load(), "save") 37 assert.Equal(t, "apex", c.Team) 38 }) 39 } 40 41 func TestConfig_env(t *testing.T) { 42 t.Run("load", func(t *testing.T) { 43 os.Setenv("UP_CONFIG", `{ "team": "tj@apex.sh" }`) 44 c := Config{} 45 assert.NoError(t, c.Load(), "load") 46 assert.Equal(t, "tj@apex.sh", c.Team) 47 }) 48 }