Add more tests to kubeadm for better coverage
parent
eadfae3e37
commit
839b493494
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
package images
|
package images
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/blang/semver"
|
"github.com/blang/semver"
|
||||||
|
@ -29,6 +30,12 @@ func Kubeadm(mirror string, version string) ([]string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "semver")
|
return nil, errors.Wrap(err, "semver")
|
||||||
}
|
}
|
||||||
|
if v.Major > 1 {
|
||||||
|
return nil, fmt.Errorf("version too new: %v", v)
|
||||||
|
}
|
||||||
|
if semver.MustParseRange("<1.11.0-alpha.0")(v) {
|
||||||
|
return nil, fmt.Errorf("version too old: %v", v)
|
||||||
|
}
|
||||||
imgs := essentials(mirror, v)
|
imgs := essentials(mirror, v)
|
||||||
imgs = append(imgs, auxiliary(mirror)...)
|
imgs = append(imgs, auxiliary(mirror)...)
|
||||||
return imgs, nil
|
return imgs, nil
|
||||||
|
|
|
@ -28,9 +28,13 @@ func TestKubeadmImages(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
version string
|
version string
|
||||||
mirror string
|
mirror string
|
||||||
|
invalid bool
|
||||||
want []string
|
want []string
|
||||||
}{
|
}{
|
||||||
{"v1.17.0", "", []string{
|
{"invalid", "", true, nil},
|
||||||
|
{"v0.0.1", "", true, nil}, // too old
|
||||||
|
{"v2.0.0", "", true, nil}, // too new
|
||||||
|
{"v1.17.0", "", false, []string{
|
||||||
"k8s.gcr.io/kube-proxy:v1.17.0",
|
"k8s.gcr.io/kube-proxy:v1.17.0",
|
||||||
"k8s.gcr.io/kube-scheduler:v1.17.0",
|
"k8s.gcr.io/kube-scheduler:v1.17.0",
|
||||||
"k8s.gcr.io/kube-controller-manager:v1.17.0",
|
"k8s.gcr.io/kube-controller-manager:v1.17.0",
|
||||||
|
@ -42,7 +46,7 @@ func TestKubeadmImages(t *testing.T) {
|
||||||
"docker.io/kubernetesui/dashboard:v2.1.0",
|
"docker.io/kubernetesui/dashboard:v2.1.0",
|
||||||
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
||||||
}},
|
}},
|
||||||
{"v1.16.1", "mirror.k8s.io", []string{
|
{"v1.16.1", "mirror.k8s.io", false, []string{
|
||||||
"mirror.k8s.io/kube-proxy:v1.16.1",
|
"mirror.k8s.io/kube-proxy:v1.16.1",
|
||||||
"mirror.k8s.io/kube-scheduler:v1.16.1",
|
"mirror.k8s.io/kube-scheduler:v1.16.1",
|
||||||
"mirror.k8s.io/kube-controller-manager:v1.16.1",
|
"mirror.k8s.io/kube-controller-manager:v1.16.1",
|
||||||
|
@ -54,7 +58,7 @@ func TestKubeadmImages(t *testing.T) {
|
||||||
"mirror.k8s.io/dashboard:v2.1.0",
|
"mirror.k8s.io/dashboard:v2.1.0",
|
||||||
"mirror.k8s.io/metrics-scraper:v1.0.4",
|
"mirror.k8s.io/metrics-scraper:v1.0.4",
|
||||||
}},
|
}},
|
||||||
{"v1.15.0", "", []string{
|
{"v1.15.0", "", false, []string{
|
||||||
"k8s.gcr.io/kube-proxy:v1.15.0",
|
"k8s.gcr.io/kube-proxy:v1.15.0",
|
||||||
"k8s.gcr.io/kube-scheduler:v1.15.0",
|
"k8s.gcr.io/kube-scheduler:v1.15.0",
|
||||||
"k8s.gcr.io/kube-controller-manager:v1.15.0",
|
"k8s.gcr.io/kube-controller-manager:v1.15.0",
|
||||||
|
@ -66,7 +70,7 @@ func TestKubeadmImages(t *testing.T) {
|
||||||
"docker.io/kubernetesui/dashboard:v2.1.0",
|
"docker.io/kubernetesui/dashboard:v2.1.0",
|
||||||
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
||||||
}},
|
}},
|
||||||
{"v1.14.0", "", []string{
|
{"v1.14.0", "", false, []string{
|
||||||
"k8s.gcr.io/kube-proxy:v1.14.0",
|
"k8s.gcr.io/kube-proxy:v1.14.0",
|
||||||
"k8s.gcr.io/kube-scheduler:v1.14.0",
|
"k8s.gcr.io/kube-scheduler:v1.14.0",
|
||||||
"k8s.gcr.io/kube-controller-manager:v1.14.0",
|
"k8s.gcr.io/kube-controller-manager:v1.14.0",
|
||||||
|
@ -78,7 +82,7 @@ func TestKubeadmImages(t *testing.T) {
|
||||||
"docker.io/kubernetesui/dashboard:v2.1.0",
|
"docker.io/kubernetesui/dashboard:v2.1.0",
|
||||||
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
||||||
}},
|
}},
|
||||||
{"v1.13.0", "", []string{
|
{"v1.13.0", "", false, []string{
|
||||||
"k8s.gcr.io/kube-proxy:v1.13.0",
|
"k8s.gcr.io/kube-proxy:v1.13.0",
|
||||||
"k8s.gcr.io/kube-scheduler:v1.13.0",
|
"k8s.gcr.io/kube-scheduler:v1.13.0",
|
||||||
"k8s.gcr.io/kube-controller-manager:v1.13.0",
|
"k8s.gcr.io/kube-controller-manager:v1.13.0",
|
||||||
|
@ -90,7 +94,7 @@ func TestKubeadmImages(t *testing.T) {
|
||||||
"docker.io/kubernetesui/dashboard:v2.1.0",
|
"docker.io/kubernetesui/dashboard:v2.1.0",
|
||||||
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
||||||
}},
|
}},
|
||||||
{"v1.12.0", "", []string{
|
{"v1.12.0", "", false, []string{
|
||||||
"k8s.gcr.io/kube-proxy:v1.12.0",
|
"k8s.gcr.io/kube-proxy:v1.12.0",
|
||||||
"k8s.gcr.io/kube-scheduler:v1.12.0",
|
"k8s.gcr.io/kube-scheduler:v1.12.0",
|
||||||
"k8s.gcr.io/kube-controller-manager:v1.12.0",
|
"k8s.gcr.io/kube-controller-manager:v1.12.0",
|
||||||
|
@ -102,11 +106,27 @@ func TestKubeadmImages(t *testing.T) {
|
||||||
"docker.io/kubernetesui/dashboard:v2.1.0",
|
"docker.io/kubernetesui/dashboard:v2.1.0",
|
||||||
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
||||||
}},
|
}},
|
||||||
|
{"v1.11.0", "", false, []string{
|
||||||
|
"k8s.gcr.io/kube-proxy:v1.11.0",
|
||||||
|
"k8s.gcr.io/kube-scheduler:v1.11.0",
|
||||||
|
"k8s.gcr.io/kube-controller-manager:v1.11.0",
|
||||||
|
"k8s.gcr.io/kube-apiserver:v1.11.0",
|
||||||
|
"k8s.gcr.io/coredns:1.1.3",
|
||||||
|
"k8s.gcr.io/etcd:3.2.18",
|
||||||
|
"k8s.gcr.io/pause:3.1",
|
||||||
|
"gcr.io/k8s-minikube/storage-provisioner:" + version.GetStorageProvisionerVersion(),
|
||||||
|
"docker.io/kubernetesui/dashboard:v2.1.0",
|
||||||
|
"docker.io/kubernetesui/metrics-scraper:v1.0.4",
|
||||||
|
}},
|
||||||
|
{"v1.10.0", "", true, nil},
|
||||||
}
|
}
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
got, err := Kubeadm(tc.mirror, tc.version)
|
got, err := Kubeadm(tc.mirror, tc.version)
|
||||||
if err != nil {
|
if err == nil && tc.invalid {
|
||||||
t.Fatalf("unexpected err: %v", err)
|
t.Fatalf("expected err (%s): %v", tc.version, got)
|
||||||
|
}
|
||||||
|
if err != nil && !tc.invalid {
|
||||||
|
t.Fatalf("unexpected err (%s): %v", tc.version, err)
|
||||||
}
|
}
|
||||||
sort.Strings(got)
|
sort.Strings(got)
|
||||||
sort.Strings(tc.want)
|
sort.Strings(tc.want)
|
||||||
|
|
Loading…
Reference in New Issue