Skip to content

Commit

Permalink
Merge pull request #11015 from afbjorklund/memory-validation
Browse files Browse the repository at this point in the history
Fix wrong error message on memory validation
  • Loading branch information
medyagh committed Apr 7, 2021
2 parents 80072ed + cc553bf commit 1854a33
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
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

0 comments on commit 1854a33

Please sign in to comment.