Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong error message on memory validation #11015

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var settings = []Setting{
{
name: "memory",
set: SetString,
validations: []setFn{IsValidDiskSize},
validations: []setFn{IsValidMemory},
callbacks: []setFn{RequiresRestartMsg},
},
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestSetNotAllowed(t *testing.T) {
t.Fatalf("Set did not return error for unallowed value: %+v", err)
}
err = Set("memory", "10a")
if err == nil || err.Error() != "run validations for \"memory\" with value of \"10a\": [invalid disk size: invalid size: '10a']" {
if err == nil || err.Error() != "run validations for \"memory\" with value of \"10a\": [invalid memory size: invalid size: '10a']" {
t.Fatalf("Set did not return error for unallowed value: %+v", err)
}
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/minikube/cmd/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ func IsValidDiskSize(name string, disksize string) error {
return nil
}

// IsValidMemory checks if a string is a valid memory size
func IsValidMemory(name string, memsize string) error {
_, err := units.FromHumanSize(memsize)
if err != nil {
return fmt.Errorf("invalid memory size: %v", err)
}
return nil
}

// IsValidURL checks if a location is a valid URL
func IsValidURL(name string, location string) error {
_, err := url.Parse(location)
Expand Down