Skip to content

Commit

Permalink
Merge pull request #6700 from medyagh/resource_limit
Browse files Browse the repository at this point in the history
fix inverted logic for resource logic
  • Loading branch information
medyagh authored Feb 20, 2020
2 parents 5169325 + 7ada4f5 commit 8700f8a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func validateFlags(cmd *cobra.Command, drvName string) {
validateDiskSize()
validateMemorySize()

if !driver.HasResourceLimits(drvName) { // both podman and none need root and they both cant specify resources
if !driver.HasResourceLimits(drvName) {
if cmd.Flags().Changed(cpus) {
out.WarningT("The '{{.name}}' driver does not respect the --cpus flag", out.V{"name": drvName})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NeedsRoot(name string) bool {

// HasResourceLimits returns true if driver can set resource limits such as memory size or CPU count.
func HasResourceLimits(name string) bool {
return name == None || name == Podman
return !(name == None || name == Podman)
}

// FlagHints are hints for what default options should be used for this driver
Expand Down
121 changes: 66 additions & 55 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,68 +494,79 @@ func validateLogsCmd(ctx context.Context, t *testing.T, profile string) {

// validateProfileCmd asserts "profile" command functionality
func validateProfileCmd(ctx context.Context, t *testing.T, profile string) {
// Profile command should not create a nonexistent profile
nonexistentProfile := "lis"
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", nonexistentProfile))
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
var profileJson map[string][]map[string]interface{}
err = json.Unmarshal(rr.Stdout.Bytes(), &profileJson)
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
for profileK := range profileJson {
for _, p := range profileJson[profileK] {
var name = p["Name"]
if (name == nonexistentProfile) {
t.Errorf("minikube profile %s should not exist", nonexistentProfile)
t.Run("profile_not_create", func(t *testing.T) {
// Profile command should not create a nonexistent profile
nonexistentProfile := "lis"
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", nonexistentProfile))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
var profileJSON map[string][]map[string]interface{}
err = json.Unmarshal(rr.Stdout.Bytes(), &profileJSON)
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
for profileK := range profileJSON {
for _, p := range profileJSON[profileK] {
var name = p["Name"]
if name == nonexistentProfile {
t.Errorf("minikube profile %s should not exist", nonexistentProfile)
}
}
}
}
})

// List profiles
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
t.Run("profile_list", func(t *testing.T) {
// List profiles
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}

// Table output
listLines := strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
profileExists := false
for i := 3; i < (len(listLines) - 1); i++ {
profileLine := listLines[i]
if strings.Contains(profileLine, profile) {
profileExists = true
break
// Table output
listLines := strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
profileExists := false
for i := 3; i < (len(listLines) - 1); i++ {
profileLine := listLines[i]
if strings.Contains(profileLine, profile) {
profileExists = true
break
}
}
if !profileExists {
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
}
}
if !profileExists {
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
}

// Json output
rr, err = Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
var jsonObject map[string][]map[string]interface{}
err = json.Unmarshal(rr.Stdout.Bytes(), &jsonObject)
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
validProfiles := jsonObject["valid"]
profileExists = false
for _, profileObject := range validProfiles {
if profileObject["Name"] == profile {
profileExists = true
break
})

t.Run("profile_json_output", func(t *testing.T) {
// Json output
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
}
if !profileExists {
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
}
var jsonObject map[string][]map[string]interface{}
err = json.Unmarshal(rr.Stdout.Bytes(), &jsonObject)
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
validProfiles := jsonObject["valid"]
profileExists := false
for _, profileObject := range validProfiles {
if profileObject["Name"] == profile {
profileExists = true
break
}
}
if !profileExists {
t.Errorf("%s failed: Missing profile '%s'. Got '\n%s\n'", rr.Args, profile, rr.Stdout.String())
}

})
}

// validateServiceCmd asserts basic "service" command functionality
Expand Down

0 comments on commit 8700f8a

Please sign in to comment.