Skip to content

Commit

Permalink
Merge pull request #906 from syself/refactor-hetznercluster-tests
Browse files Browse the repository at this point in the history
🌱 Refactor tests of hetznercluster controller
  • Loading branch information
janiskemper authored Sep 12, 2023
2 parents 336d56b + b66f191 commit ce79857
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 682 deletions.
12 changes: 10 additions & 2 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ func getDefaultHetznerBareMetalMachineSpec() infrav1.HetznerBareMetalMachineSpec
}

func isPresentAndFalseWithReason(key types.NamespacedName, getter conditions.Getter, condition clusterv1.ConditionType, reason string) bool {
ExpectWithOffset(1, testEnv.Get(ctx, key, getter)).To(Succeed())
err := testEnv.Get(ctx, key, getter)
if err != nil {
return false
}

if !conditions.Has(getter, condition) {
return false
}
Expand All @@ -258,7 +262,11 @@ func isPresentAndFalseWithReason(key types.NamespacedName, getter conditions.Get
}

func isPresentAndTrue(key types.NamespacedName, getter conditions.Getter, condition clusterv1.ConditionType) bool {
ExpectWithOffset(1, testEnv.Get(ctx, key, getter)).To(Succeed())
err := testEnv.Get(ctx, key, getter)
if err != nil {
return false
}

if !conditions.Has(getter, condition) {
return false
}
Expand Down
20 changes: 0 additions & 20 deletions controllers/hcloudmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -495,25 +494,6 @@ var _ = Describe("Hetzner secret", func() {

AfterEach(func() {
Expect(testEnv.Cleanup(ctx, hetznerCluster, capiCluster, hcloudMachine, capiMachine, hetznerSecret)).To(Succeed())

Eventually(func() bool {
if err := testEnv.Get(ctx, client.ObjectKey{Namespace: hetznerSecret.Namespace, Name: hetznerSecret.Name}, hetznerSecret); err != nil && apierrors.IsNotFound(err) {
return true
} else if err != nil {
return false
}
// Secret still there, so the finalizers have not been removed. Patch to remove them.
ph, err := patch.NewHelper(hetznerSecret, testEnv)
Expect(err).ShouldNot(HaveOccurred())
hetznerSecret.Finalizers = nil
Expect(ph.Patch(ctx, hetznerSecret, patch.WithStatusObservedGeneration{})).To(Succeed())
// Should delete secret
if err := testEnv.Delete(ctx, hetznerSecret); err != nil && apierrors.IsNotFound(err) {
// Has been deleted already
return true
}
return false
}, time.Second, time.Second).Should(BeTrue())
})

DescribeTable("test different hetzner secret",
Expand Down
Loading

0 comments on commit ce79857

Please sign in to comment.