55package config
66
77import (
8+ "os"
89 "strings"
910 "testing"
11+ "strconv"
12+ "math/rand"
1013
14+ "github.com/scaleway/scaleway-cli/pkg/scwversion"
1115 . "github.com/smartystreets/goconvey/convey"
1216)
1317
@@ -23,6 +27,49 @@ func TestGetConfigFilePath(t *testing.T) {
2327 })
2428}
2529
30+ func TestGetConfigFilePathEnv (t * testing.T ) {
31+ Convey ("Testing GetConfigFilePath() with env variable" , t , func () {
32+ os .Setenv ("SCW_CONFIG_PATH" , "./config_testdata1" )
33+ configPath , err := GetConfigFilePath ()
34+ So (err , ShouldBeNil )
35+ So (configPath , ShouldEqual , "./config_testdata1" )
36+ os .Unsetenv ("SCW_CONFIG_PATH" )
37+ })
38+ }
39+
40+ func TestGetConfig (t * testing.T ) {
41+ Convey ("Testing GetConfig() with env variable" , t , func () {
42+ os .Setenv ("SCW_CONFIG_PATH" , "./config_testdata1" )
43+ config , err := GetConfig ()
44+ So (err , ShouldBeNil )
45+ So (config .Version , ShouldEqual , "test_version" )
46+ So (config .Organization , ShouldEqual , "test_orgID" )
47+ So (config .Token , ShouldEqual , "test_token" )
48+ os .Unsetenv ("SCW_CONFIG_PATH" )
49+ })
50+ }
51+
52+ func TestSave (t * testing.T ) {
53+ Convey ("Testing SaveConfig() with env variable" , t , func () {
54+ os .Setenv ("SCW_CONFIG_PATH" , "./config_testdata2" )
55+ randOrg := strconv .FormatInt (rand .Int63 (), 16 )
56+ randToken := strconv .FormatInt (rand .Int63 (), 16 )
57+ cfg := & Config {
58+ Organization : strings .Trim (randOrg , "\n " ),
59+ Token : strings .Trim (randToken , "\n " ),
60+ }
61+ err := cfg .Save ()
62+ So (err , ShouldBeNil )
63+ So (cfg .Version , ShouldEqual , scwversion .VERSION )
64+ So (cfg .Organization , ShouldEqual , randOrg )
65+ So (cfg .Token , ShouldEqual , randToken )
66+ os .Unsetenv ("SCW_CONFIG_PATH" )
67+ })
68+ }
69+
70+
71+
72+
2673func TestGetHomeDir (t * testing.T ) {
2774 Convey ("Testing GetHomeDir()" , t , func () {
2875 homedir , err := GetHomeDir ()
0 commit comments