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

Don't allow creating profile by profile command #6672

Merged
merged 5 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
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})
},
}
20 changes: 19 additions & 1 deletion test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,25 @@ 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))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
for _, line := range []string{fmt.Sprintf("Created a new profile : %s", nonexistentProfile), fmt.Sprintf("minikube profile was successfully set to %s", nonexistentProfile)} {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about instead of parsing the output, do a
"minikube profile list --output=json" and expect not to see the "lis" in the created profiles?

Copy link
Contributor Author

@aallbrig aallbrig Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! I’ll update it today

if strings.Contains(rr.Stdout.String(), line) {
t.Errorf("minikube profile should not create a nonexistent profile")
}
}
for _, line := range []string{fmt.Sprintf("profile \"%s\" not found", nonexistentProfile), fmt.Sprintf("if you want to create a profile you can by this command: minikube start -p %s", nonexistentProfile)} {
if !strings.Contains(rr.Stderr.String(), line) {
t.Errorf("minikube profile should provide guidance on how to create a nonexistent profile")
}
}

// 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