提交 a840cb72 编写于 作者: K Kenta Iso

Fix update-context to use KUBECONFIG when the env is set and add integration test

上级 87a0e4ef
......@@ -17,6 +17,8 @@ limitations under the License.
package cmd
import (
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/cluster"
......@@ -45,7 +47,13 @@ var updateContextCmd = &cobra.Command{
if err != nil {
exit.WithError("Error host driver ip status", err)
}
updated, err := kubeconfig.UpdateIP(ip, machineName, constants.KubeconfigPath)
updated := false
kubeConfigPath := os.Getenv("KUBECONFIG")
if kubeConfigPath == "" {
updated, err = kubeconfig.UpdateIP(ip, machineName, constants.KubeconfigPath)
} else {
updated, err = kubeconfig.UpdateIP(ip, machineName, kubeConfigPath)
}
if err != nil {
exit.WithError("update config", err)
}
......
......@@ -103,6 +103,7 @@ func TestFunctional(t *testing.T) {
{"SSHCmd", validateSSHCmd},
{"MySQL", validateMySQL},
{"FileSync", validateFileSync},
{"UpdateContextCmd", validateUpdateContextCmd},
}
for _, tc := range tests {
tc := tc
......@@ -645,6 +646,19 @@ func validateFileSync(ctx context.Context, t *testing.T, profile string) {
}
}
// validateUpdateContextCmd asserts basic "update-context" command functionality
func validateUpdateContextCmd(ctx context.Context, t *testing.T, profile string) {
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "update-context", "--alsologtostderr", "-v=2"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
want := []byte("IP was already correctly configured")
if !bytes.Contains(rr.Stdout.Bytes(), want) {
t.Errorf("update-context: got=%q, want=*%q*", rr.Stdout.Bytes(), want)
}
}
// startHTTPProxy runs a local http proxy and sets the env vars for it.
func startHTTPProxy(t *testing.T) (*http.Server, error) {
port, err := freeport.GetFreePort()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册