minikube/pkg/addons/kubectl_test.go

63 lines
1.7 KiB
Go
Raw Normal View History

2019-12-10 18:08:23 +00:00
/*
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 addons
import (
2019-12-10 21:06:22 +00:00
"strings"
2019-12-10 18:08:23 +00:00
"testing"
"k8s.io/minikube/pkg/minikube/config"
2019-12-10 18:08:23 +00:00
)
func TestKubectlCommand(t *testing.T) {
2020-01-14 20:12:47 +00:00
tests := []struct {
description string
2020-01-22 22:23:32 +00:00
files []string
enable bool
2020-01-14 20:12:47 +00:00
expected string
}{
{
2020-01-22 22:23:32 +00:00
description: "enable an addon",
files: []string{"a", "b"},
enable: true,
expected: "sudo KUBECONFIG=/var/lib/minikube/kubeconfig /var/lib/minikube/binaries/v1.17.0/kubectl apply -f a -f b",
2020-01-14 20:12:47 +00:00
}, {
2020-01-22 22:23:32 +00:00
description: "disable an addon",
files: []string{"a", "b"},
enable: false,
expected: "sudo KUBECONFIG=/var/lib/minikube/kubeconfig /var/lib/minikube/binaries/v1.17.0/kubectl delete -f a -f b",
2020-01-14 20:12:47 +00:00
},
}
cc := &config.ClusterConfig{
KubernetesConfig: config.KubernetesConfig{
KubernetesVersion: "v1.17.0",
},
}
2020-01-14 20:12:47 +00:00
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
command := kubectlCommand(cc, test.files, test.enable)
2020-01-14 20:12:47 +00:00
actual := strings.Join(command.Args, " ")
2020-01-22 22:23:32 +00:00
if actual != test.expected {
t.Fatalf("expected does not match actual\nExpected: %s\nActual: %s", test.expected, actual)
2020-01-14 20:12:47 +00:00
}
})
2019-12-10 21:06:22 +00:00
}
2019-12-10 18:08:23 +00:00
}