Skip to content

Commit

Permalink
controlplane pkg tests delete namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriyMikhalkin committed Jul 19, 2021
1 parent 37db485 commit 144a1c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions controlplane/kubeadm/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func TestReconcileReturnErrorWhenOwnerClusterIsMissing(t *testing.T) {
cluster, kcp, _ := createClusterWithControlPlane(ns.Name)
g.Expect(env.Create(ctx, cluster)).To(Succeed())
g.Expect(env.Create(ctx, kcp)).To(Succeed())
defer func(do ...client.Object) {
g.Expect(env.Cleanup(ctx, do...)).To(Succeed())
}(kcp, ns)

r := &KubeadmControlPlaneReconciler{
Client: env,
Expand Down Expand Up @@ -168,6 +171,9 @@ func TestReconcileUpdateObservedGeneration(t *testing.T) {
cluster, kcp, _ := createClusterWithControlPlane(ns.Name)
g.Expect(env.Create(ctx, cluster)).To(Succeed())
g.Expect(env.Create(ctx, kcp)).To(Succeed())
defer func(do ...client.Object) {
g.Expect(env.Cleanup(ctx, do...)).To(Succeed())
}(cluster, kcp, ns)

// read kcp.Generation after create
errGettingObject := env.Get(ctx, util.ObjectKey(kcp), kcp)
Expand Down
9 changes: 6 additions & 3 deletions controlplane/kubeadm/controllers/remediation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func TestReconcileUnhealthyMachines(t *testing.T) {
}
ns, err := env.CreateNamespace(ctx, "ns1")
g.Expect(err).ToNot(HaveOccurred())
defer func() {
g.Expect(env.Cleanup(ctx, ns)).To(Succeed())
}()

t.Run("Remediation does not happen if there are no unhealthy machines", func(t *testing.T) {
g := NewWithT(t)
Expand Down Expand Up @@ -361,8 +364,6 @@ func TestReconcileUnhealthyMachines(t *testing.T) {

g.Expect(env.Cleanup(ctx, m1, m2, m3, m4)).To(Succeed())
})

g.Expect(env.Cleanup(ctx, ns)).To(Succeed())
}

func TestCanSafelyRemoveEtcdMember(t *testing.T) {
Expand All @@ -371,6 +372,9 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {

ns, err := env.CreateNamespace(ctx, "ns1")
g.Expect(err).ToNot(HaveOccurred())
defer func() {
g.Expect(env.Cleanup(ctx, ns)).To(Succeed())
}()

t.Run("Can't safely remediate 1 machine CP", func(t *testing.T) {
g := NewWithT(t)
Expand Down Expand Up @@ -734,7 +738,6 @@ func TestCanSafelyRemoveEtcdMember(t *testing.T) {

g.Expect(env.Cleanup(ctx, m1, m2, m3, m4, m5, m6, m7)).To(Succeed())
})
g.Expect(env.Cleanup(ctx, ns)).To(Succeed())
}

func nodes(machines collections.Machines) []string {
Expand Down

0 comments on commit 144a1c2

Please sign in to comment.