Skip to content

Commit

Permalink
Improve UnsetTest
Browse files Browse the repository at this point in the history
  • Loading branch information
josedonizetti committed Jul 30, 2019
1 parent 45a329f commit 483fe64
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 20 additions & 1 deletion cmd/minikube/cmd/config/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package config

import "testing"
import (
"testing"

"k8s.io/minikube/pkg/minikube/config"
)

func TestUnsetConfig(t *testing.T) {
propName := "cpus"
Expand All @@ -25,8 +29,23 @@ func TestUnsetConfig(t *testing.T) {
if err != nil {
t.Errorf("Failed to set the property %q", propName)
}

cpus, err := config.Get("cpus")
if err != nil {
t.Errorf("Failed to read config %q", err)
}

if cpus != propValue {
t.Errorf("Expected cpus to be %s but got %s", propValue, cpus)
}

err = Unset(propName)
if err != nil {
t.Errorf("Failed to unset property %q", err)
}

_, err = config.Get("cpus")
if err != config.ErrKeyNotFound {
t.Errorf("Expected error %q but got %q", config.ErrKeyNotFound, err)
}
}
7 changes: 6 additions & 1 deletion pkg/minikube/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const (
ShowBootstrapperDeprecationNotification = "ShowBootstrapperDeprecationNotification"
)

var (
// ErrKeyNotFound is the error returned when a key doesn't exist in the config file
ErrKeyNotFound = errors.New("specified key could not be found in config")
)

// MinikubeConfig represents minikube config
type MinikubeConfig map[string]interface{}

Expand All @@ -66,7 +71,7 @@ func get(name string, config MinikubeConfig) (string, error) {
if val, ok := config[name]; ok {
return fmt.Sprintf("%v", val), nil
}
return "", errors.New("specified key could not be found in config")
return "", ErrKeyNotFound
}

// ReadConfig reads in the JSON minikube config
Expand Down

0 comments on commit 483fe64

Please sign in to comment.