From 089deef706660a6d8f3966ab1d62006f2ba1bf73 Mon Sep 17 00:00:00 2001 From: aallbright Date: Mon, 17 Feb 2020 19:08:00 -0500 Subject: [PATCH 1/4] Do not create profiles that do not exist --- cmd/minikube/cmd/config/profile.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmd/minikube/cmd/config/profile.go b/cmd/minikube/cmd/config/profile.go index 778402408970..280bb1c237ad 100644 --- a/cmd/minikube/cmd/config/profile.go +++ b/cmd/minikube/cmd/config/profile.go @@ -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) @@ -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}) }, } From ff873d272817689bee017f009542c2b2bc0882b8 Mon Sep 17 00:00:00 2001 From: aallbright Date: Tue, 18 Feb 2020 07:10:27 -0500 Subject: [PATCH 2/4] Add tests around nonexistent profiles --- test/integration/functional_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index bb4efa3701a5..3aa4f95cdb9a 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -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 _, word := range []string{fmt.Sprintf("Created a new profile : %s", nonexistentProfile), fmt.Sprintf("minikube profile was successfully set to %s", nonexistentProfile)} { + if strings.Contains(rr.Stdout.String(), word) { + t.Errorf("minikube profile should not create a nonexistent profile") + } + } + for _, word := 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(), word) { + 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) } From addb2e623ed203706bd51ea11d5a4e7899f7ea74 Mon Sep 17 00:00:00 2001 From: aallbright Date: Tue, 18 Feb 2020 19:00:57 -0500 Subject: [PATCH 3/4] word -> line --- test/integration/functional_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 3aa4f95cdb9a..6751f5617d5a 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -500,13 +500,13 @@ func validateProfileCmd(ctx context.Context, t *testing.T, profile string) { if err != nil { t.Errorf("%s failed: %v", rr.Args, err) } - for _, word := range []string{fmt.Sprintf("Created a new profile : %s", nonexistentProfile), fmt.Sprintf("minikube profile was successfully set to %s", nonexistentProfile)} { - if strings.Contains(rr.Stdout.String(), word) { + for _, line := range []string{fmt.Sprintf("Created a new profile : %s", nonexistentProfile), fmt.Sprintf("minikube profile was successfully set to %s", nonexistentProfile)} { + if strings.Contains(rr.Stdout.String(), line) { t.Errorf("minikube profile should not create a nonexistent profile") } } - for _, word := 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(), word) { + 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") } } From 020c0f3d939f6a16f8d2b87d8fd8f0c92d38dff1 Mon Sep 17 00:00:00 2001 From: aallbright Date: Wed, 19 Feb 2020 22:56:32 -0500 Subject: [PATCH 4/4] Use JSON output to determine desired behavior --- test/integration/functional_test.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 6751f5617d5a..75f0446c0839 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -497,17 +497,21 @@ 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) } - for _, line := range []string{fmt.Sprintf("Created a new profile : %s", nonexistentProfile), fmt.Sprintf("minikube profile was successfully set to %s", nonexistentProfile)} { - if strings.Contains(rr.Stdout.String(), line) { - t.Errorf("minikube profile should not create a nonexistent profile") - } + 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 _, 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") + 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) + } } }