提交 58288cfb 编写于 作者: J josedonizetti 提交者: Medya Gh

Add test to config ReadConfig

上级 27664fe1
...@@ -76,7 +76,11 @@ func get(name string, config MinikubeConfig) (string, error) { ...@@ -76,7 +76,11 @@ func get(name string, config MinikubeConfig) (string, error) {
// ReadConfig reads in the JSON minikube config // ReadConfig reads in the JSON minikube config
func ReadConfig() (MinikubeConfig, error) { func ReadConfig() (MinikubeConfig, error) {
f, err := os.Open(constants.ConfigFile) return readConfig(constants.ConfigFile)
}
func readConfig(configFile string) (MinikubeConfig, error) {
f, err := os.Open(configFile)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return make(map[string]interface{}), nil return make(map[string]interface{}), nil
......
...@@ -101,3 +101,43 @@ func TestGet(t *testing.T) { ...@@ -101,3 +101,43 @@ func TestGet(t *testing.T) {
} }
} }
} }
func Test_readConfig(t *testing.T) {
// non existing file
mkConfig, err := readConfig("non_existing_file")
if err != nil {
t.Fatalf("Error not exepected but got %v", err)
}
if len(mkConfig) != 0 {
t.Errorf("Expected empty map but got %v", mkConfig)
}
// invalid config file
mkConfig, err = readConfig("./testdata/.minikube/config/invalid_config.json")
if err == nil {
t.Fatalf("Error expected but got none")
}
if mkConfig != nil {
t.Errorf("Expected nil but got %v", mkConfig)
}
// valid config file
mkConfig, err = readConfig("./testdata/.minikube/config/valid_config.json")
if err != nil {
t.Fatalf("Error not expected but got %v", err)
}
expectedConfig := map[string]interface{}{
"vm-driver": constants.DriverKvm2,
"cpus": 4,
"disk-size": "20g",
"show-libmachine-logs": true,
"log_dir": "/etc/hosts",
}
if reflect.DeepEqual(expectedConfig, mkConfig) || err != nil {
t.Errorf("Did not read config correctly,\n\n wanted %+v, \n\n got %+v", expectedConfig, mkConfig)
}
}
{
"vm-driver": "kvm2",
"cpus": 4,
"disk-size": "20g",
"show-libmachine-logs": true,
"log_dir": "/etc/hosts"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册