From 4738d1a80f71a7411d71b85d600b0014f8d85b08 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Sat, 17 Aug 2019 12:08:38 -0400 Subject: [PATCH 01/10] Refactor config.ReadConfig to accept a file --- cmd/minikube/cmd/cache.go | 2 +- cmd/minikube/cmd/config/config.go | 6 +++--- cmd/minikube/cmd/config/set.go | 2 +- cmd/minikube/cmd/config/unset.go | 2 +- cmd/minikube/cmd/config/view.go | 2 +- pkg/minikube/config/config.go | 8 ++------ pkg/minikube/config/config_test.go | 10 +++++----- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/cmd/minikube/cmd/cache.go b/cmd/minikube/cmd/cache.go index 8192a9e0d3..b2795e4851 100644 --- a/cmd/minikube/cmd/cache.go +++ b/cmd/minikube/cmd/cache.go @@ -67,7 +67,7 @@ var deleteCacheCmd = &cobra.Command{ } func imagesInConfigFile() ([]string, error) { - configFile, err := config.ReadConfig() + configFile, err := config.ReadConfig(constants.ConfigFile) if err != nil { return nil, err } diff --git a/cmd/minikube/cmd/config/config.go b/cmd/minikube/cmd/config/config.go index 9e3d9d637b..66779daec9 100644 --- a/cmd/minikube/cmd/config/config.go +++ b/cmd/minikube/cmd/config/config.go @@ -290,7 +290,7 @@ func configurableFields() string { // ListConfigMap list entries from config file func ListConfigMap(name string) ([]string, error) { - configFile, err := config.ReadConfig() + configFile, err := config.ReadConfig(constants.ConfigFile) if err != nil { return nil, err } @@ -310,7 +310,7 @@ func AddToConfigMap(name string, images []string) error { return err } // Set the values - cfg, err := config.ReadConfig() + cfg, err := config.ReadConfig(constants.ConfigFile) if err != nil { return err } @@ -337,7 +337,7 @@ func DeleteFromConfigMap(name string, images []string) error { return err } // Set the values - cfg, err := config.ReadConfig() + cfg, err := config.ReadConfig(constants.ConfigFile) if err != nil { return err } diff --git a/cmd/minikube/cmd/config/set.go b/cmd/minikube/cmd/config/set.go index 3019c793e2..c1db6372a4 100644 --- a/cmd/minikube/cmd/config/set.go +++ b/cmd/minikube/cmd/config/set.go @@ -56,7 +56,7 @@ func Set(name string, value string) error { } // Set the value - config, err := pkgConfig.ReadConfig() + config, err := pkgConfig.ReadConfig(constants.ConfigFile) if err != nil { return err } diff --git a/cmd/minikube/cmd/config/unset.go b/cmd/minikube/cmd/config/unset.go index fc91390ed8..ee9cff74f4 100644 --- a/cmd/minikube/cmd/config/unset.go +++ b/cmd/minikube/cmd/config/unset.go @@ -44,7 +44,7 @@ func init() { // Unset unsets a property func Unset(name string) error { - m, err := pkgConfig.ReadConfig() + m, err := pkgConfig.ReadConfig(constants.ConfigFile) if err != nil { return err } diff --git a/cmd/minikube/cmd/config/view.go b/cmd/minikube/cmd/config/view.go index 3ea025e922..33f79e12cd 100644 --- a/cmd/minikube/cmd/config/view.go +++ b/cmd/minikube/cmd/config/view.go @@ -55,7 +55,7 @@ For the list of accessible variables for the template, see the struct values her // View displays the current config func View() error { - cfg, err := config.ReadConfig() + cfg, err := config.ReadConfig(constants.ConfigFile) if err != nil { return err } diff --git a/pkg/minikube/config/config.go b/pkg/minikube/config/config.go index d8a7636e7c..18d568fc0c 100644 --- a/pkg/minikube/config/config.go +++ b/pkg/minikube/config/config.go @@ -59,7 +59,7 @@ type MinikubeConfig map[string]interface{} // Get gets a named value from config func Get(name string) (string, error) { - m, err := ReadConfig() + m, err := ReadConfig(constants.ConfigFile) if err != nil { return "", err } @@ -88,11 +88,7 @@ func WriteConfig(configFile string, m MinikubeConfig) error { } // ReadConfig reads in the JSON minikube config -func ReadConfig() (MinikubeConfig, error) { - return readConfig(constants.ConfigFile) -} - -func readConfig(configFile string) (MinikubeConfig, error) { +func ReadConfig(configFile string) (MinikubeConfig, error) { f, err := os.Open(configFile) if err != nil { if os.IsNotExist(err) { diff --git a/pkg/minikube/config/config_test.go b/pkg/minikube/config/config_test.go index b6390a2ae3..d1c7254c1a 100644 --- a/pkg/minikube/config/config_test.go +++ b/pkg/minikube/config/config_test.go @@ -104,9 +104,9 @@ func Test_get(t *testing.T) { } } -func Test_readConfig(t *testing.T) { +func TestReadConfig(t *testing.T) { // non existing file - mkConfig, err := readConfig("non_existing_file") + mkConfig, err := ReadConfig("non_existing_file") if err != nil { t.Fatalf("Error not exepected but got %v", err) } @@ -116,7 +116,7 @@ func Test_readConfig(t *testing.T) { } // invalid config file - mkConfig, err = readConfig("./testdata/.minikube/config/invalid_config.json") + mkConfig, err = ReadConfig("./testdata/.minikube/config/invalid_config.json") if err == nil { t.Fatalf("Error expected but got none") } @@ -126,7 +126,7 @@ func Test_readConfig(t *testing.T) { } // valid config file - mkConfig, err = readConfig("./testdata/.minikube/config/valid_config.json") + mkConfig, err = ReadConfig("./testdata/.minikube/config/valid_config.json") if err != nil { t.Fatalf("Error not expected but got %v", err) } @@ -164,7 +164,7 @@ func TestWriteConfig(t *testing.T) { } defer os.Remove(configFile.Name()) - mkConfig, err := readConfig(configFile.Name()) + mkConfig, err := ReadConfig(configFile.Name()) if err != nil { t.Fatalf("Error not expected but got %v", err) } From 69dfac387dbd261275b1e6ba7ca16768196e6604 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Mon, 19 Aug 2019 19:31:56 -0400 Subject: [PATCH 02/10] Add config integration test --- test/integration/fn_minikube_config.go | 47 ++++++++++++++++++++++++++ test/integration/functional_test.go | 1 + 2 files changed, 48 insertions(+) create mode 100644 test/integration/fn_minikube_config.go diff --git a/test/integration/fn_minikube_config.go b/test/integration/fn_minikube_config.go new file mode 100644 index 0000000000..25ceb45529 --- /dev/null +++ b/test/integration/fn_minikube_config.go @@ -0,0 +1,47 @@ +// +build integration + +/* +Copyright 2016 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import ( + "testing" +) + +func testMinikubeConfig(t *testing.T) { + t.Parallel() + p := profileName(t) + mk := NewMinikubeRunner(t, p, "--wait=false") + + tests := []struct { + cmd string + output string + }{ + {"config get memory", "Error: specified key could not be found in config"}, + {"config set memory 4016", "! These changes will take effect upon a minikube delete and then a minikube start"}, + {"config get memory", "4016"}, + {"config unset memory", ""}, + {"config get memory", "Error: specified key could not be found in config"}, + } + + for _, test := range tests { + sshCmdOutput, stderr := mk.RunCommand(t.cmd) + if !strings.Contains(sshCmdOutput, t.output) { + t.Fatalf("ExpectedStr sshCmdOutput to be: %s. Output was: %s Stderr: %s", expectedStr, sshCmdOutput, stderr) + } + } +} diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index bae1efded5..d020b1a10b 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -49,6 +49,7 @@ func TestFunctional(t *testing.T) { t.Run("Provisioning", testProvisioning) t.Run("Tunnel", testTunnel) t.Run("kubecontext", testKubeConfigCurrentCtx) + t.Run("minikubeConfig", testMinikubeConfig) if !isTestNoneDriver(t) { t.Run("EnvVars", testClusterEnv) From 911ce1276d898d9c85dc490eebef64cc0a1724ff Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Mon, 19 Aug 2019 20:08:52 -0400 Subject: [PATCH 03/10] Rename integration to testConfig --- test/integration/{fn_minikube_config.go => fn_config.go} | 4 ++-- test/integration/functional_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename test/integration/{fn_minikube_config.go => fn_config.go} (93%) diff --git a/test/integration/fn_minikube_config.go b/test/integration/fn_config.go similarity index 93% rename from test/integration/fn_minikube_config.go rename to test/integration/fn_config.go index 25ceb45529..e32cb8d003 100644 --- a/test/integration/fn_minikube_config.go +++ b/test/integration/fn_config.go @@ -1,7 +1,7 @@ // +build integration /* -Copyright 2016 The Kubernetes Authors All rights reserved. +Copyright 2019 The Kubernetes Authors All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import ( "testing" ) -func testMinikubeConfig(t *testing.T) { +func testConfig(t *testing.T) { t.Parallel() p := profileName(t) mk := NewMinikubeRunner(t, p, "--wait=false") diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index d020b1a10b..85516a51d8 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -49,7 +49,7 @@ func TestFunctional(t *testing.T) { t.Run("Provisioning", testProvisioning) t.Run("Tunnel", testTunnel) t.Run("kubecontext", testKubeConfigCurrentCtx) - t.Run("minikubeConfig", testMinikubeConfig) + t.Run("config", testConfig) if !isTestNoneDriver(t) { t.Run("EnvVars", testClusterEnv) From 0843e01c94b2d68ef31e1af493cc7eb1e83a86f2 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Mon, 19 Aug 2019 20:11:23 -0400 Subject: [PATCH 04/10] Change testConfig to use default cpus --- test/integration/fn_config.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/integration/fn_config.go b/test/integration/fn_config.go index e32cb8d003..dade0bb58f 100644 --- a/test/integration/fn_config.go +++ b/test/integration/fn_config.go @@ -31,11 +31,11 @@ func testConfig(t *testing.T) { cmd string output string }{ - {"config get memory", "Error: specified key could not be found in config"}, - {"config set memory 4016", "! These changes will take effect upon a minikube delete and then a minikube start"}, - {"config get memory", "4016"}, - {"config unset memory", ""}, - {"config get memory", "Error: specified key could not be found in config"}, + {"config get cpus", "Error: specified key could not be found in config"}, + {"config set cpus 2", "! These changes will take effect upon a minikube delete and then a minikube start"}, + {"config get cpus", "2"}, + {"config unset cpus", ""}, + {"config get cpus", "Error: specified key could not be found in config"}, } for _, test := range tests { From 06da850ed7f90518465b1d5db1c5e95ff85d1c50 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Mon, 19 Aug 2019 20:23:07 -0400 Subject: [PATCH 05/10] Change testConfig profile name --- test/integration/fn_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/fn_config.go b/test/integration/fn_config.go index dade0bb58f..80a5de6e5a 100644 --- a/test/integration/fn_config.go +++ b/test/integration/fn_config.go @@ -24,7 +24,7 @@ import ( func testConfig(t *testing.T) { t.Parallel() - p := profileName(t) + p := profileName(t) + "config" mk := NewMinikubeRunner(t, p, "--wait=false") tests := []struct { From 15f6e90ce2c88c2a0d3d0116846e00a995d4788f Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Mon, 19 Aug 2019 20:35:59 -0400 Subject: [PATCH 06/10] Fix testConfig --- test/integration/fn_config.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/integration/fn_config.go b/test/integration/fn_config.go index 80a5de6e5a..2c92f9e83c 100644 --- a/test/integration/fn_config.go +++ b/test/integration/fn_config.go @@ -19,6 +19,8 @@ limitations under the License. package integration import ( + "strings" + "testing" ) @@ -39,9 +41,9 @@ func testConfig(t *testing.T) { } for _, test := range tests { - sshCmdOutput, stderr := mk.RunCommand(t.cmd) - if !strings.Contains(sshCmdOutput, t.output) { - t.Fatalf("ExpectedStr sshCmdOutput to be: %s. Output was: %s Stderr: %s", expectedStr, sshCmdOutput, stderr) + sshCmdOutput, stderr := mk.RunCommand(test.cmd, true) + if !strings.Contains(sshCmdOutput, test.output) { + t.Fatalf("ExpectedStr sshCmdOutput to be: %s. Output was: %s Stderr: %s", test.output, sshCmdOutput, stderr) } } } From 11bd62a625c245e260715aa8e642b4b9c9c1a2e7 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Tue, 20 Aug 2019 08:58:57 -0400 Subject: [PATCH 07/10] Extract TestConfig from TestFunction --- test/integration/config_test.go | 92 +++++++++++++++++++++++++++++ test/integration/fn_config.go | 49 --------------- test/integration/functional_test.go | 1 - 3 files changed, 92 insertions(+), 50 deletions(-) create mode 100644 test/integration/config_test.go delete mode 100644 test/integration/fn_config.go diff --git a/test/integration/config_test.go b/test/integration/config_test.go new file mode 100644 index 0000000000..8b1cba706c --- /dev/null +++ b/test/integration/config_test.go @@ -0,0 +1,92 @@ +// +build integration + +/* +Copyright 2019 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import ( + "io" + "strings" + "testing" +) + +func TestConfig(t *testing.T) { + t.Parallel() + p := profileName(t) + mk := NewMinikubeRunner(t, p, "--wait=false") + + tests := []struct { + cmd string + stdout string + stderr string + }{ + { + cmd: "config unset cpus", + stdout: "", + stderr: "", + }, + { + cmd: "config get cpus", + stdout: "", + stderr: "Error: specified key could not be found in config", + }, + { + cmd: "config set cpus 2", + stdout: "! These changes will take effect upon a minikube delete and then a minikube start", + stderr: "", + }, + { + cmd: "config get cpus", + stdout: "2", + stderr: "", + }, + { + cmd: "config unset cpus", + stdout: "", + stderr: ""}, + { + cmd: "config get cpus", + stdout: "", + stderr: "Error: specified key could not be found in config", + }, + } + + for _, test := range tests { + _, stdoutReader, stderrReader := mk.RunDaemon2(test.cmd) + + stdout, err := stdoutReader.ReadString('\n') + if err != nil && err != io.EOF { + t.Fatalf("Error not expected but got: %v", err) + } + + stderr, err := stderrReader.ReadString('\n') + if err != nil && err != io.EOF { + t.Fatalf("Error not expected but got: %v", err) + } + + if !compare(test.stdout, stdout) { + t.Fatalf("Expected stdout to be: %s. Stdout was: %s Stderr: %s", test.stdout, stdout, stderr) + } + if !compare(test.stderr, stderr) { + t.Fatalf("Expected stderr to be: %s. Stdout was: %s Stderr: %s", test.stderr, stdout, stderr) + } + } +} + +func compare(s1, s2 string) bool { + return strings.TrimSpace(s1) == strings.TrimSpace(s2) +} diff --git a/test/integration/fn_config.go b/test/integration/fn_config.go deleted file mode 100644 index 2c92f9e83c..0000000000 --- a/test/integration/fn_config.go +++ /dev/null @@ -1,49 +0,0 @@ -// +build integration - -/* -Copyright 2019 The Kubernetes Authors All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package integration - -import ( - "strings" - - "testing" -) - -func testConfig(t *testing.T) { - t.Parallel() - p := profileName(t) + "config" - mk := NewMinikubeRunner(t, p, "--wait=false") - - tests := []struct { - cmd string - output string - }{ - {"config get cpus", "Error: specified key could not be found in config"}, - {"config set cpus 2", "! These changes will take effect upon a minikube delete and then a minikube start"}, - {"config get cpus", "2"}, - {"config unset cpus", ""}, - {"config get cpus", "Error: specified key could not be found in config"}, - } - - for _, test := range tests { - sshCmdOutput, stderr := mk.RunCommand(test.cmd, true) - if !strings.Contains(sshCmdOutput, test.output) { - t.Fatalf("ExpectedStr sshCmdOutput to be: %s. Output was: %s Stderr: %s", test.output, sshCmdOutput, stderr) - } - } -} diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 85516a51d8..bae1efded5 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -49,7 +49,6 @@ func TestFunctional(t *testing.T) { t.Run("Provisioning", testProvisioning) t.Run("Tunnel", testTunnel) t.Run("kubecontext", testKubeConfigCurrentCtx) - t.Run("config", testConfig) if !isTestNoneDriver(t) { t.Run("EnvVars", testClusterEnv) From 5e45bb22975d64a54db3ba2627251488855993ae Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Tue, 20 Aug 2019 09:17:20 -0400 Subject: [PATCH 08/10] Fix doc --- test/integration/util/minikube_runner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/util/minikube_runner.go b/test/integration/util/minikube_runner.go index 19c766e248..51d1340a6c 100644 --- a/test/integration/util/minikube_runner.go +++ b/test/integration/util/minikube_runner.go @@ -124,7 +124,7 @@ func (m *MinikubeRunner) RunCommand(cmdStr string, failError bool, waitForRun .. return stdout, stderr } -// RunCommandRetriable Error executes a command, returns error +// RunCommandRetriable executes a command, returns error // the purpose of this command is to make it retriable and // better logging for retrying func (m *MinikubeRunner) RunCommandRetriable(cmdStr string, waitForRun ...bool) (stdout string, stderr string, err error) { From 19364326b10a0d78ac3d0ad245b0445522696d2a Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Tue, 20 Aug 2019 09:19:40 -0400 Subject: [PATCH 09/10] Change TestConfig to use RunCommandRetriable --- test/integration/config_test.go | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/test/integration/config_test.go b/test/integration/config_test.go index 8b1cba706c..6b3a522f21 100644 --- a/test/integration/config_test.go +++ b/test/integration/config_test.go @@ -19,7 +19,6 @@ limitations under the License. package integration import ( - "io" "strings" "testing" ) @@ -66,17 +65,7 @@ func TestConfig(t *testing.T) { } for _, test := range tests { - _, stdoutReader, stderrReader := mk.RunDaemon2(test.cmd) - - stdout, err := stdoutReader.ReadString('\n') - if err != nil && err != io.EOF { - t.Fatalf("Error not expected but got: %v", err) - } - - stderr, err := stderrReader.ReadString('\n') - if err != nil && err != io.EOF { - t.Fatalf("Error not expected but got: %v", err) - } + stdout, stderr, _ := mk.RunCommandRetriable(test.cmd) if !compare(test.stdout, stdout) { t.Fatalf("Expected stdout to be: %s. Stdout was: %s Stderr: %s", test.stdout, stdout, stderr) From 1ed3f4481b27452816ffa73925057c3380335f45 Mon Sep 17 00:00:00 2001 From: josedonizetti Date: Wed, 21 Aug 2019 10:53:48 -0400 Subject: [PATCH 10/10] Improve variable naming --- test/integration/config_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/integration/config_test.go b/test/integration/config_test.go index 6b3a522f21..626f84266f 100644 --- a/test/integration/config_test.go +++ b/test/integration/config_test.go @@ -64,14 +64,14 @@ func TestConfig(t *testing.T) { }, } - for _, test := range tests { - stdout, stderr, _ := mk.RunCommandRetriable(test.cmd) + for _, tc := range tests { + stdout, stderr, _ := mk.RunCommandRetriable(tc.cmd) - if !compare(test.stdout, stdout) { - t.Fatalf("Expected stdout to be: %s. Stdout was: %s Stderr: %s", test.stdout, stdout, stderr) + if !compare(tc.stdout, stdout) { + t.Fatalf("Expected stdout to be: %s. Stdout was: %s Stderr: %s", tc.stdout, stdout, stderr) } - if !compare(test.stderr, stderr) { - t.Fatalf("Expected stderr to be: %s. Stdout was: %s Stderr: %s", test.stderr, stdout, stderr) + if !compare(tc.stderr, stderr) { + t.Fatalf("Expected stderr to be: %s. Stdout was: %s Stderr: %s", tc.stderr, stdout, stderr) } } }