Skip to content

Commit

Permalink
rename import
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Jul 7, 2020
1 parent 294dd50 commit ac25a9e
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions controlplane/kubeadm/internal/machinefilters/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"testing"

Ω "github.com/onsi/gomega"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -33,13 +33,13 @@ import (

func TestMatchClusterConfiguration(t *testing.T) {
t.Run("machine without the ClusterConfiguration annotation should match (not enough information to make a decision)", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{}
m := &clusterv1.Machine{}
g.Expect(matchClusterConfiguration(kcp, m)).To(Ω.BeTrue())
g.Expect(matchClusterConfiguration(kcp, m)).To(gomega.BeTrue())
})
t.Run("machine without an invalid ClusterConfiguration annotation should not match (only solution is to rollout)", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{}
m := &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -48,10 +48,10 @@ func TestMatchClusterConfiguration(t *testing.T) {
},
},
}
g.Expect(matchClusterConfiguration(kcp, m)).To(Ω.BeFalse())
g.Expect(matchClusterConfiguration(kcp, m)).To(gomega.BeFalse())
})
t.Run("Return true if cluster configuration matches", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand All @@ -68,10 +68,10 @@ func TestMatchClusterConfiguration(t *testing.T) {
},
},
}
g.Expect(matchClusterConfiguration(kcp, m)).To(Ω.BeTrue())
g.Expect(matchClusterConfiguration(kcp, m)).To(gomega.BeTrue())
})
t.Run("Return false if cluster configuration does not match", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand All @@ -88,13 +88,13 @@ func TestMatchClusterConfiguration(t *testing.T) {
},
},
}
g.Expect(matchClusterConfiguration(kcp, m)).To(Ω.BeFalse())
g.Expect(matchClusterConfiguration(kcp, m)).To(gomega.BeFalse())
})
}

func TestGetAdjustedKcpConfig(t *testing.T) {
t.Run("if the machine is the first control plane, kcp config should get InitConfiguration", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand All @@ -109,11 +109,11 @@ func TestGetAdjustedKcpConfig(t *testing.T) {
},
}
kcpConfig := getAdjustedKcpConfig(kcp, machineConfig)
g.Expect(kcpConfig.InitConfiguration).ToNot(Ω.BeNil())
g.Expect(kcpConfig.JoinConfiguration).To(Ω.BeNil())
g.Expect(kcpConfig.InitConfiguration).ToNot(gomega.BeNil())
g.Expect(kcpConfig.JoinConfiguration).To(gomega.BeNil())
})
t.Run("if the machine is a joining control plane, kcp config should get JoinConfiguration", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand All @@ -128,14 +128,14 @@ func TestGetAdjustedKcpConfig(t *testing.T) {
},
}
kcpConfig := getAdjustedKcpConfig(kcp, machineConfig)
g.Expect(kcpConfig.InitConfiguration).To(Ω.BeNil())
g.Expect(kcpConfig.JoinConfiguration).ToNot(Ω.BeNil())
g.Expect(kcpConfig.InitConfiguration).To(gomega.BeNil())
g.Expect(kcpConfig.JoinConfiguration).ToNot(gomega.BeNil())
})
}

func TestCleanupConfigFields(t *testing.T) {
t.Run("ClusterConfiguration gets removed from KcpConfig and MachineConfig", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
ClusterConfiguration: &kubeadmv1beta1.ClusterConfiguration{},
}
Expand All @@ -145,11 +145,11 @@ func TestCleanupConfigFields(t *testing.T) {
},
}
cleanupConfigFields(kcpConfig, machineConfig)
g.Expect(kcpConfig.ClusterConfiguration).To(Ω.BeNil())
g.Expect(machineConfig.Spec.ClusterConfiguration).To(Ω.BeNil())
g.Expect(kcpConfig.ClusterConfiguration).To(gomega.BeNil())
g.Expect(machineConfig.Spec.ClusterConfiguration).To(gomega.BeNil())
})
t.Run("JoinConfiguration gets removed from MachineConfig if it was not derived by KCPConfig", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
JoinConfiguration: nil, // KCP not providing a JoinConfiguration
}
Expand All @@ -159,11 +159,11 @@ func TestCleanupConfigFields(t *testing.T) {
},
}
cleanupConfigFields(kcpConfig, machineConfig)
g.Expect(kcpConfig.JoinConfiguration).To(Ω.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration).To(Ω.BeNil())
g.Expect(kcpConfig.JoinConfiguration).To(gomega.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration).To(gomega.BeNil())
})
t.Run("JoinConfiguration.Discovery gets removed because it is not relevant for compare", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
JoinConfiguration: &kubeadmv1beta1.JoinConfiguration{
Discovery: kubeadmv1beta1.Discovery{TLSBootstrapToken: "aaa"},
Expand All @@ -177,11 +177,11 @@ func TestCleanupConfigFields(t *testing.T) {
},
}
cleanupConfigFields(kcpConfig, machineConfig)
g.Expect(kcpConfig.JoinConfiguration.Discovery).To(Ω.Equal(kubeadmv1beta1.Discovery{}))
g.Expect(machineConfig.Spec.JoinConfiguration.Discovery).To(Ω.Equal(kubeadmv1beta1.Discovery{}))
g.Expect(kcpConfig.JoinConfiguration.Discovery).To(gomega.Equal(kubeadmv1beta1.Discovery{}))
g.Expect(machineConfig.Spec.JoinConfiguration.Discovery).To(gomega.Equal(kubeadmv1beta1.Discovery{}))
})
t.Run("JoinConfiguration.ControlPlane gets removed from MachineConfig if it was not derived by KCPConfig", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
JoinConfiguration: &kubeadmv1beta1.JoinConfiguration{
ControlPlane: nil, // Control plane configuration missing in KCP
Expand All @@ -195,11 +195,11 @@ func TestCleanupConfigFields(t *testing.T) {
},
}
cleanupConfigFields(kcpConfig, machineConfig)
g.Expect(kcpConfig.JoinConfiguration).ToNot(Ω.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration.ControlPlane).To(Ω.BeNil())
g.Expect(kcpConfig.JoinConfiguration).ToNot(gomega.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration.ControlPlane).To(gomega.BeNil())
})
t.Run("JoinConfiguration.NodeRegistrationOptions gets removed from MachineConfig if it was not derived by KCPConfig", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
JoinConfiguration: &kubeadmv1beta1.JoinConfiguration{
NodeRegistration: kubeadmv1beta1.NodeRegistrationOptions{}, // NodeRegistrationOptions configuration missing in KCP
Expand All @@ -213,11 +213,11 @@ func TestCleanupConfigFields(t *testing.T) {
},
}
cleanupConfigFields(kcpConfig, machineConfig)
g.Expect(kcpConfig.JoinConfiguration).ToNot(Ω.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration.NodeRegistration).To(Ω.Equal(kubeadmv1beta1.NodeRegistrationOptions{}))
g.Expect(kcpConfig.JoinConfiguration).ToNot(gomega.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration.NodeRegistration).To(gomega.Equal(kubeadmv1beta1.NodeRegistrationOptions{}))
})
t.Run("InitConfiguration.TypeMeta gets removed from MachineConfig", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
InitConfiguration: &kubeadmv1beta1.InitConfiguration{},
}
Expand All @@ -232,11 +232,11 @@ func TestCleanupConfigFields(t *testing.T) {
},
}
cleanupConfigFields(kcpConfig, machineConfig)
g.Expect(kcpConfig.InitConfiguration).ToNot(Ω.BeNil())
g.Expect(machineConfig.Spec.InitConfiguration.TypeMeta).To(Ω.Equal(metav1.TypeMeta{}))
g.Expect(kcpConfig.InitConfiguration).ToNot(gomega.BeNil())
g.Expect(machineConfig.Spec.InitConfiguration.TypeMeta).To(gomega.Equal(metav1.TypeMeta{}))
})
t.Run("JoinConfiguration.TypeMeta gets removed from MachineConfig", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcpConfig := &bootstrapv1.KubeadmConfigSpec{
JoinConfiguration: &kubeadmv1beta1.JoinConfiguration{},
}
Expand All @@ -251,22 +251,22 @@ func TestCleanupConfigFields(t *testing.T) {
},
}
cleanupConfigFields(kcpConfig, machineConfig)
g.Expect(kcpConfig.JoinConfiguration).ToNot(Ω.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration.TypeMeta).To(Ω.Equal(metav1.TypeMeta{}))
g.Expect(kcpConfig.JoinConfiguration).ToNot(gomega.BeNil())
g.Expect(machineConfig.Spec.JoinConfiguration.TypeMeta).To(gomega.Equal(metav1.TypeMeta{}))
})
}

func TestMatchInitOrJoinConfiguration(t *testing.T) {
scheme := runtime.NewScheme()
_ = bootstrapv1.AddToScheme(scheme)
t.Run("returns true if the machine does not have bootstrap config", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{}
m := &clusterv1.Machine{}
g.Expect(matchInitOrJoinConfiguration(context.TODO(), nil, kcp, m)).To(Ω.BeTrue())
g.Expect(matchInitOrJoinConfiguration(context.TODO(), nil, kcp, m)).To(gomega.BeTrue())
})
t.Run("returns true if the there are problems reading the bootstrap config", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{}
m := &clusterv1.Machine{
Spec: clusterv1.MachineSpec{
Expand All @@ -276,10 +276,10 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
},
}
client := fake.NewFakeClientWithScheme(scheme)
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(Ω.BeTrue())
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(gomega.BeTrue())
})
t.Run("returns true if InitConfiguration is equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -323,10 +323,10 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
},
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(Ω.BeTrue())
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(gomega.BeTrue())
})
t.Run("returns false if InitConfiguration is NOT equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -374,10 +374,10 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
},
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(Ω.BeFalse())
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(gomega.BeFalse())
})
t.Run("returns true if JoinConfiguration is equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -421,10 +421,10 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
},
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(Ω.BeTrue())
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(gomega.BeTrue())
})
t.Run("returns false if JoinConfiguration is NOT equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -472,10 +472,10 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
},
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(Ω.BeFalse())
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(gomega.BeFalse())
})
t.Run("returns false if some other configurations are not equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -520,15 +520,15 @@ func TestMatchInitOrJoinConfiguration(t *testing.T) {
},
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(Ω.BeFalse())
g.Expect(matchInitOrJoinConfiguration(context.TODO(), client, kcp, m)).To(gomega.BeFalse())
})
}

func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
scheme := runtime.NewScheme()
_ = bootstrapv1.AddToScheme(scheme)
t.Run("returns true if ClusterConfiguration is equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand All @@ -548,10 +548,10 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
machineConfig := &bootstrapv1.KubeadmConfig{}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
f := MatchesKubeadmBootstrapConfig(context.TODO(), client, kcp)
g.Expect(f(m)).To(Ω.BeTrue())
g.Expect(f(m)).To(gomega.BeTrue())
})
t.Run("returns false if ClusterConfiguration is NOT equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand All @@ -571,10 +571,10 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
machineConfig := &bootstrapv1.KubeadmConfig{}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
f := MatchesKubeadmBootstrapConfig(context.TODO(), client, kcp)
g.Expect(f(m)).To(Ω.BeFalse())
g.Expect(f(m)).To(gomega.BeFalse())
})
t.Run("returns true if InitConfiguration is equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -619,10 +619,10 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
f := MatchesKubeadmBootstrapConfig(context.TODO(), client, kcp)
g.Expect(f(m)).To(Ω.BeTrue())
g.Expect(f(m)).To(gomega.BeTrue())
})
t.Run("returns false if InitConfiguration is NOT equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -671,10 +671,10 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
f := MatchesKubeadmBootstrapConfig(context.TODO(), client, kcp)
g.Expect(f(m)).To(Ω.BeFalse())
g.Expect(f(m)).To(gomega.BeFalse())
})
t.Run("returns true if JoinConfiguration is equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -719,10 +719,10 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
f := MatchesKubeadmBootstrapConfig(context.TODO(), client, kcp)
g.Expect(f(m)).To(Ω.BeTrue())
g.Expect(f(m)).To(gomega.BeTrue())
})
t.Run("returns false if JoinConfiguration is NOT equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -771,10 +771,10 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
f := MatchesKubeadmBootstrapConfig(context.TODO(), client, kcp)
g.Expect(f(m)).To(Ω.BeFalse())
g.Expect(f(m)).To(gomega.BeFalse())
})
t.Run("returns false if some other configurations are not equal", func(t *testing.T) {
g := Ω.NewWithT(t)
g := gomega.NewWithT(t)
kcp := &controlplanev1.KubeadmControlPlane{
Spec: controlplanev1.KubeadmControlPlaneSpec{
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
Expand Down Expand Up @@ -820,6 +820,6 @@ func TestMatchesKubeadmBootstrapConfig(t *testing.T) {
}
client := fake.NewFakeClientWithScheme(scheme, machineConfig)
f := MatchesKubeadmBootstrapConfig(context.TODO(), client, kcp)
g.Expect(f(m)).To(Ω.BeFalse())
g.Expect(f(m)).To(gomega.BeFalse())
})
}

0 comments on commit ac25a9e

Please sign in to comment.