Skip to content

Commit

Permalink
Merge pull request #6672 from aallbrig/profile-command-improvement
Browse files Browse the repository at this point in the history
Profile command should not create non existent profiles
  • Loading branch information
medyagh authored Feb 20, 2020
2 parents 9123e72 + 020c0f3 commit a5c76f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 2 additions & 6 deletions cmd/minikube/cmd/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ var ProfileCmd = &cobra.Command{
}

if !pkgConfig.ProfileExists(profile) {
err := pkgConfig.CreateEmptyProfile(profile)
if err != nil {
exit.WithError("Creating a new profile failed", err)
}
out.SuccessT("Created a new profile : {{.profile_name}}", out.V{"profile_name": profile})
out.FailureT("if you want to create a profile you can by this command: minikube start -p {{.profile_name}}", out.V{"profile_name": profile})
}

err := Set(pkgConfig.MachineProfile, profile)
Expand All @@ -91,7 +87,7 @@ var ProfileCmd = &cobra.Command{
out.ErrT(out.Sad, `Error while setting kubectl current context : {{.error}}`, out.V{"error": err})
}
}
out.SuccessT("minikube profile was successfully set to {{.profile_name}}", out.V{"profile_name": profile})
}
out.SuccessT("minikube profile was successfully set to {{.profile_name}}", out.V{"profile_name": profile})
},
}
24 changes: 23 additions & 1 deletion test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,29 @@ 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) {
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list"))
// 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)
}
}
}

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

0 comments on commit a5c76f8

Please sign in to comment.