mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
kubeadm: use t.Run in selfhosting and update phases
Used T.Run API for kubeadm tests in app/phases/selfhosting and app/phases/update directories This should improve testing output and make it more visible which test is doing what.
This commit is contained in:
parent
716b253963
commit
442098bdec
@ -27,11 +27,13 @@ import (
|
|||||||
|
|
||||||
func TestMutatePodSpec(t *testing.T) {
|
func TestMutatePodSpec(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
component string
|
component string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "mutate api server podspec",
|
||||||
component: kubeadmconstants.KubeAPIServer,
|
component: kubeadmconstants.KubeAPIServer,
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
@ -73,6 +75,7 @@ func TestMutatePodSpec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "mutate controller manager podspec",
|
||||||
component: kubeadmconstants.KubeControllerManager,
|
component: kubeadmconstants.KubeControllerManager,
|
||||||
podSpec: &v1.PodSpec{},
|
podSpec: &v1.PodSpec{},
|
||||||
expected: v1.PodSpec{
|
expected: v1.PodSpec{
|
||||||
@ -86,6 +89,7 @@ func TestMutatePodSpec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "mutate scheduler podspec",
|
||||||
component: kubeadmconstants.KubeScheduler,
|
component: kubeadmconstants.KubeScheduler,
|
||||||
podSpec: &v1.PodSpec{},
|
podSpec: &v1.PodSpec{},
|
||||||
expected: v1.PodSpec{
|
expected: v1.PodSpec{
|
||||||
@ -101,20 +105,24 @@ func TestMutatePodSpec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
mutatePodSpec(GetDefaultMutators(), rt.component, rt.podSpec)
|
mutatePodSpec(GetDefaultMutators(), rt.component, rt.podSpec)
|
||||||
|
|
||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed mutatePodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed mutatePodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddNodeSelectorToPodSpec(t *testing.T) {
|
func TestAddNodeSelectorToPodSpec(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "empty podspec",
|
||||||
podSpec: &v1.PodSpec{},
|
podSpec: &v1.PodSpec{},
|
||||||
expected: v1.PodSpec{
|
expected: v1.PodSpec{
|
||||||
NodeSelector: map[string]string{
|
NodeSelector: map[string]string{
|
||||||
@ -123,6 +131,7 @@ func TestAddNodeSelectorToPodSpec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "podspec with a valid node selector",
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
NodeSelector: map[string]string{
|
NodeSelector: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
@ -138,20 +147,24 @@ func TestAddNodeSelectorToPodSpec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
addNodeSelectorToPodSpec(rt.podSpec)
|
addNodeSelectorToPodSpec(rt.podSpec)
|
||||||
|
|
||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed addNodeSelectorToPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed addNodeSelectorToPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetMasterTolerationOnPodSpec(t *testing.T) {
|
func TestSetMasterTolerationOnPodSpec(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "empty podspec",
|
||||||
podSpec: &v1.PodSpec{},
|
podSpec: &v1.PodSpec{},
|
||||||
expected: v1.PodSpec{
|
expected: v1.PodSpec{
|
||||||
Tolerations: []v1.Toleration{
|
Tolerations: []v1.Toleration{
|
||||||
@ -160,6 +173,7 @@ func TestSetMasterTolerationOnPodSpec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "podspec with a valid toleration",
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
Tolerations: []v1.Toleration{
|
Tolerations: []v1.Toleration{
|
||||||
{Key: "foo", Value: "bar"},
|
{Key: "foo", Value: "bar"},
|
||||||
@ -175,26 +189,31 @@ func TestSetMasterTolerationOnPodSpec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
setMasterTolerationOnPodSpec(rt.podSpec)
|
setMasterTolerationOnPodSpec(rt.podSpec)
|
||||||
|
|
||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed setMasterTolerationOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed setMasterTolerationOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetRightDNSPolicyOnPodSpec(t *testing.T) {
|
func TestSetRightDNSPolicyOnPodSpec(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "empty podspec",
|
||||||
podSpec: &v1.PodSpec{},
|
podSpec: &v1.PodSpec{},
|
||||||
expected: v1.PodSpec{
|
expected: v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirstWithHostNet,
|
DNSPolicy: v1.DNSClusterFirstWithHostNet,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "podspec with a v1.DNSClusterFirst policy",
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
DNSPolicy: v1.DNSClusterFirst,
|
DNSPolicy: v1.DNSClusterFirst,
|
||||||
},
|
},
|
||||||
@ -205,20 +224,24 @@ func TestSetRightDNSPolicyOnPodSpec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
setRightDNSPolicyOnPodSpec(rt.podSpec)
|
setRightDNSPolicyOnPodSpec(rt.podSpec)
|
||||||
|
|
||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed setRightDNSPolicyOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed setRightDNSPolicyOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetHostIPOnPodSpec(t *testing.T) {
|
func TestSetHostIPOnPodSpec(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "set HOST_IP env var on a podspec",
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
{
|
{
|
||||||
@ -254,21 +277,25 @@ func TestSetHostIPOnPodSpec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
setHostIPOnPodSpec(rt.podSpec)
|
setHostIPOnPodSpec(rt.podSpec)
|
||||||
|
|
||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed setHostIPOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed setHostIPOnPodSpec:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetSelfHostedVolumesForAPIServer(t *testing.T) {
|
func TestSetSelfHostedVolumesForAPIServer(t *testing.T) {
|
||||||
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
|
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "set selfhosted volumes for api server",
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
{
|
{
|
||||||
@ -346,6 +373,7 @@ func TestSetSelfHostedVolumesForAPIServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
setSelfHostedVolumesForAPIServer(rt.podSpec)
|
setSelfHostedVolumesForAPIServer(rt.podSpec)
|
||||||
sort.Strings(rt.podSpec.Containers[0].Command)
|
sort.Strings(rt.podSpec.Containers[0].Command)
|
||||||
sort.Strings(rt.expected.Containers[0].Command)
|
sort.Strings(rt.expected.Containers[0].Command)
|
||||||
@ -353,6 +381,7 @@ func TestSetSelfHostedVolumesForAPIServer(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed setSelfHostedVolumesForAPIServer:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed setSelfHostedVolumesForAPIServer:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,10 +389,12 @@ func TestSetSelfHostedVolumesForControllerManager(t *testing.T) {
|
|||||||
hostPathFileOrCreate := v1.HostPathFileOrCreate
|
hostPathFileOrCreate := v1.HostPathFileOrCreate
|
||||||
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
|
hostPathDirectoryOrCreate := v1.HostPathDirectoryOrCreate
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "set selfhosted volumes for controller mananger",
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
{
|
{
|
||||||
@ -464,6 +495,7 @@ func TestSetSelfHostedVolumesForControllerManager(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
setSelfHostedVolumesForControllerManager(rt.podSpec)
|
setSelfHostedVolumesForControllerManager(rt.podSpec)
|
||||||
sort.Strings(rt.podSpec.Containers[0].Command)
|
sort.Strings(rt.podSpec.Containers[0].Command)
|
||||||
sort.Strings(rt.expected.Containers[0].Command)
|
sort.Strings(rt.expected.Containers[0].Command)
|
||||||
@ -471,16 +503,19 @@ func TestSetSelfHostedVolumesForControllerManager(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed setSelfHostedVolumesForControllerManager:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed setSelfHostedVolumesForControllerManager:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetSelfHostedVolumesForScheduler(t *testing.T) {
|
func TestSetSelfHostedVolumesForScheduler(t *testing.T) {
|
||||||
hostPathFileOrCreate := v1.HostPathFileOrCreate
|
hostPathFileOrCreate := v1.HostPathFileOrCreate
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
name string
|
||||||
podSpec *v1.PodSpec
|
podSpec *v1.PodSpec
|
||||||
expected v1.PodSpec
|
expected v1.PodSpec
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "set selfhosted volumes for scheduler",
|
||||||
podSpec: &v1.PodSpec{
|
podSpec: &v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
{
|
{
|
||||||
@ -534,6 +569,7 @@ func TestSetSelfHostedVolumesForScheduler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
setSelfHostedVolumesForScheduler(rt.podSpec)
|
setSelfHostedVolumesForScheduler(rt.podSpec)
|
||||||
sort.Strings(rt.podSpec.Containers[0].Command)
|
sort.Strings(rt.podSpec.Containers[0].Command)
|
||||||
sort.Strings(rt.expected.Containers[0].Command)
|
sort.Strings(rt.expected.Containers[0].Command)
|
||||||
@ -541,5 +577,6 @@ func TestSetSelfHostedVolumesForScheduler(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
if !reflect.DeepEqual(*rt.podSpec, rt.expected) {
|
||||||
t.Errorf("failed setSelfHostedVolumesForScheduler:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
t.Errorf("failed setSelfHostedVolumesForScheduler:\nexpected:\n%v\nsaw:\n%v", rt.expected, *rt.podSpec)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -488,6 +488,7 @@ func TestBuildDaemonSet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.component, func(t *testing.T) {
|
||||||
tempFile, err := createTempFileWithContent(rt.podBytes)
|
tempFile, err := createTempFileWithContent(rt.podBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error creating tempfile with content:%v", err)
|
t.Errorf("error creating tempfile with content:%v", err)
|
||||||
@ -508,21 +509,23 @@ func TestBuildDaemonSet(t *testing.T) {
|
|||||||
if !bytes.Equal(dsBytes, rt.dsBytes) {
|
if !bytes.Equal(dsBytes, rt.dsBytes) {
|
||||||
t.Errorf("failed TestBuildDaemonSet:\nexpected:\n%s\nsaw:\n%s", rt.dsBytes, dsBytes)
|
t.Errorf("failed TestBuildDaemonSet:\nexpected:\n%s\nsaw:\n%s", rt.dsBytes, dsBytes)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadPodSpecFromFile(t *testing.T) {
|
func TestLoadPodSpecFromFile(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
content string
|
content string
|
||||||
expectError bool
|
expectError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
// No content
|
name: "no content",
|
||||||
content: "",
|
content: "",
|
||||||
expectError: true,
|
expectError: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Good YAML
|
name: "valid YAML",
|
||||||
content: `
|
content: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
@ -535,7 +538,7 @@ spec:
|
|||||||
expectError: false,
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Good JSON
|
name: "valid JSON",
|
||||||
content: `
|
content: `
|
||||||
{
|
{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
@ -554,7 +557,7 @@ spec:
|
|||||||
expectError: false,
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Bad PodSpec
|
name: "incorrect PodSpec",
|
||||||
content: `
|
content: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
@ -568,6 +571,7 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
tempFile, err := createTempFileWithContent([]byte(rt.content))
|
tempFile, err := createTempFileWithContent([]byte(rt.content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error creating tempfile with content:%v", err)
|
t.Errorf("error creating tempfile with content:%v", err)
|
||||||
@ -578,12 +582,15 @@ spec:
|
|||||||
if (err != nil) != rt.expectError {
|
if (err != nil) != rt.expectError {
|
||||||
t.Errorf("failed TestLoadPodSpecFromFile:\nexpected error:\n%t\nsaw:\n%v", rt.expectError, err)
|
t.Errorf("failed TestLoadPodSpecFromFile:\nexpected error:\n%t\nsaw:\n%v", rt.expectError, err)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("empty file name", func(t *testing.T) {
|
||||||
_, err := loadPodSpecFromFile("")
|
_, err := loadPodSpecFromFile("")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("unexpected success: loadPodSpecFromFile should return error when no file is given")
|
t.Error("unexpected success: loadPodSpecFromFile should return error when no file is given")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTempFileWithContent(content []byte) (string, error) {
|
func createTempFileWithContent(content []byte) (string, error) {
|
||||||
|
@ -781,18 +781,21 @@ func TestGetAvailableUpgrades(t *testing.T) {
|
|||||||
|
|
||||||
func TestKubeletUpgrade(t *testing.T) {
|
func TestKubeletUpgrade(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
before map[string]uint16
|
before map[string]uint16
|
||||||
after string
|
after string
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{ // upgrade available
|
{
|
||||||
|
name: "upgrade from v1.10.1 to v1.10.3 is available",
|
||||||
before: map[string]uint16{
|
before: map[string]uint16{
|
||||||
"v1.10.1": 1,
|
"v1.10.1": 1,
|
||||||
},
|
},
|
||||||
after: "v1.10.3",
|
after: "v1.10.3",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{ // upgrade available
|
{
|
||||||
|
name: "upgrade from v1.10.1 and v1.10.3/100 to v1.10.3 is available",
|
||||||
before: map[string]uint16{
|
before: map[string]uint16{
|
||||||
"v1.10.1": 1,
|
"v1.10.1": 1,
|
||||||
"v1.10.3": 100,
|
"v1.10.3": 100,
|
||||||
@ -800,21 +803,24 @@ func TestKubeletUpgrade(t *testing.T) {
|
|||||||
after: "v1.10.3",
|
after: "v1.10.3",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{ // upgrade not available
|
{
|
||||||
|
name: "upgrade from v1.10.3 to v1.10.3 is not available",
|
||||||
before: map[string]uint16{
|
before: map[string]uint16{
|
||||||
"v1.10.3": 1,
|
"v1.10.3": 1,
|
||||||
},
|
},
|
||||||
after: "v1.10.3",
|
after: "v1.10.3",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{ // upgrade not available
|
{
|
||||||
|
name: "upgrade from v1.10.3/100 to v1.10.3 is not available",
|
||||||
before: map[string]uint16{
|
before: map[string]uint16{
|
||||||
"v1.10.3": 100,
|
"v1.10.3": 100,
|
||||||
},
|
},
|
||||||
after: "v1.10.3",
|
after: "v1.10.3",
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{ // upgrade not available if we don't know anything about the earlier state
|
{
|
||||||
|
name: "upgrade is not available if we don't know anything about the earlier state",
|
||||||
before: map[string]uint16{},
|
before: map[string]uint16{},
|
||||||
after: "v1.10.3",
|
after: "v1.10.3",
|
||||||
expected: false,
|
expected: false,
|
||||||
@ -822,7 +828,7 @@ func TestKubeletUpgrade(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
upgrade := Upgrade{
|
upgrade := Upgrade{
|
||||||
Before: ClusterState{
|
Before: ClusterState{
|
||||||
KubeletVersions: rt.before,
|
KubeletVersions: rt.before,
|
||||||
@ -835,6 +841,7 @@ func TestKubeletUpgrade(t *testing.T) {
|
|||||||
if actual != rt.expected {
|
if actual != rt.expected {
|
||||||
t.Errorf("failed TestKubeletUpgrade\n\texpected: %t\n\tgot: %t\n\ttest object: %v", rt.expected, actual, upgrade)
|
t.Errorf("failed TestKubeletUpgrade\n\texpected: %t\n\tgot: %t\n\ttest object: %v", rt.expected, actual, upgrade)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -883,10 +890,11 @@ func TestGetBranchFromVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.version, func(t *testing.T) {
|
||||||
v := getBranchFromVersion(tc.version)
|
v := getBranchFromVersion(tc.version)
|
||||||
if v != tc.expectedVersion {
|
if v != tc.expectedVersion {
|
||||||
t.Errorf("expected version %s, got %s", tc.expectedVersion, v)
|
t.Errorf("expected version %s, got %s", tc.expectedVersion, v)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -150,6 +150,7 @@ func TestShouldBackupAPIServerCertAndKey(t *testing.T) {
|
|||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
|
t.Run(desc, func(t *testing.T) {
|
||||||
tmpdir := testutil.SetupTempDir(t)
|
tmpdir := testutil.SetupTempDir(t)
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
cfg.CertificatesDir = tmpdir
|
cfg.CertificatesDir = tmpdir
|
||||||
@ -180,5 +181,6 @@ func TestShouldBackupAPIServerCertAndKey(t *testing.T) {
|
|||||||
if shouldBackup != test.expected {
|
if shouldBackup != test.expected {
|
||||||
t.Fatalf("Test %s: shouldBackupAPIServerCertAndKey expected %v, got %v", desc, test.expected, shouldBackup)
|
t.Fatalf("Test %s: shouldBackupAPIServerCertAndKey expected %v, got %v", desc, test.expected, shouldBackup)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,26 +108,31 @@ func (p *goodPrepuller) DeleteFunc(component string) error {
|
|||||||
|
|
||||||
func TestPrepullImagesInParallel(t *testing.T) {
|
func TestPrepullImagesInParallel(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
name string
|
||||||
p Prepuller
|
p Prepuller
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
expectedErr bool
|
expectedErr bool
|
||||||
}{
|
}{
|
||||||
{ // should error out; create failed
|
{
|
||||||
|
name: "should error out; create failed",
|
||||||
p: NewFailedCreatePrepuller(),
|
p: NewFailedCreatePrepuller(),
|
||||||
timeout: 10 * time.Second,
|
timeout: 10 * time.Second,
|
||||||
expectedErr: true,
|
expectedErr: true,
|
||||||
},
|
},
|
||||||
{ // should error out; timeout exceeded
|
{
|
||||||
|
name: "should error out; timeout exceeded",
|
||||||
p: NewForeverWaitPrepuller(),
|
p: NewForeverWaitPrepuller(),
|
||||||
timeout: 10 * time.Second,
|
timeout: 10 * time.Second,
|
||||||
expectedErr: true,
|
expectedErr: true,
|
||||||
},
|
},
|
||||||
{ // should error out; delete failed
|
{
|
||||||
|
name: "should error out; delete failed",
|
||||||
p: NewFailedDeletePrepuller(),
|
p: NewFailedDeletePrepuller(),
|
||||||
timeout: 10 * time.Second,
|
timeout: 10 * time.Second,
|
||||||
expectedErr: true,
|
expectedErr: true,
|
||||||
},
|
},
|
||||||
{ // should work just fine
|
{
|
||||||
|
name: "should work just fine",
|
||||||
p: NewGoodPrepuller(),
|
p: NewGoodPrepuller(),
|
||||||
timeout: 10 * time.Second,
|
timeout: 10 * time.Second,
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
@ -135,7 +140,7 @@ func TestPrepullImagesInParallel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
actualErr := PrepullImagesInParallel(rt.p, rt.timeout, append(constants.MasterComponents, constants.Etcd))
|
actualErr := PrepullImagesInParallel(rt.p, rt.timeout, append(constants.MasterComponents, constants.Etcd))
|
||||||
if (actualErr != nil) != rt.expectedErr {
|
if (actualErr != nil) != rt.expectedErr {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
@ -144,5 +149,6 @@ func TestPrepullImagesInParallel(t *testing.T) {
|
|||||||
(actualErr != nil),
|
(actualErr != nil),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,6 +412,7 @@ func TestStaticPodControlPlane(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
|
t.Run(rt.description, func(t *testing.T) {
|
||||||
waiter := NewFakeStaticPodWaiter(rt.waitErrsToReturn)
|
waiter := NewFakeStaticPodWaiter(rt.waitErrsToReturn)
|
||||||
pathMgr, err := NewFakeStaticPodPathManager(rt.moveFileFunc)
|
pathMgr, err := NewFakeStaticPodPathManager(rt.moveFileFunc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -521,7 +522,7 @@ func TestStaticPodControlPlane(t *testing.T) {
|
|||||||
newHash,
|
newHash,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user