Skip to content

Commit

Permalink
Fix no-limit option for config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Oct 30, 2023
1 parent 51f509e commit 407c000
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func IsValidDiskSize(_, disksize string) error {

// IsValidCPUs checks if a string is a valid number of CPUs
func IsValidCPUs(name, cpus string) error {
if cpus == constants.MaxResources {
if cpus == constants.MaxResources || cpus == constants.NoLimit {
return nil
}
return IsPositive(name, cpus)
}

// IsValidMemory checks if a string is a valid memory size
func IsValidMemory(_, memsize string) error {
if memsize == constants.MaxResources {
if memsize == constants.MaxResources || memsize == constants.NoLimit {
return nil
}
_, err := units.FromHumanSize(memsize)
Expand Down
28 changes: 28 additions & 0 deletions cmd/minikube/cmd/config/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,31 @@ func TestIsURLExists(t *testing.T) {

runValidations(t, tests, "url", IsURLExists)
}

func TestIsValidCPUs(t *testing.T) {
tests := []validationTest{
{"2", false},
{"16", false},
{"max", false},
{"no-limit", false},
{"abc", true},
{"-2", true},
{"", true},
}

runValidations(t, tests, "cpus", IsValidCPUs)
}

func TestIsValidMemory(t *testing.T) {
tests := []validationTest{
{"4000mb", false},
{"8gb", false},
{"max", false},
{"no-limit", false},
{"-4000", true},
{"abc", true},
{"", true},
}

runValidations(t, tests, "memory", IsValidMemory)
}

0 comments on commit 407c000

Please sign in to comment.