Skip to content

Commit

Permalink
🌱Change test
Browse files Browse the repository at this point in the history
  • Loading branch information
yrs147 committed Aug 12, 2024
1 parent 7a8c3f1 commit 7661ac1
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions pkg/services/hcloud/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/hetznercloud/hcloud-go/v2/hcloud"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand Down Expand Up @@ -355,20 +354,15 @@ var _ = Describe("Test handleRateLimit", func() {
DescribeTable("Test handleRateLimit",
func(tc testCaseHandleRateLimit) {
err := handleRateLimit(tc.hm, tc.err, tc.functionName, tc.errMsg)
if tc.expectError != nil && hcloud.IsError(err, hcloud.ErrorCodeRateLimitExceeded) {
Expect(err).To(MatchError(tc.expectError))
Expect(isPresentAndFalseWithReason(tc.hm, infrav1.HetznerAPIReachableCondition, infrav1.RateLimitExceededReason)).To(BeTrue())
}
if tc.expectError != nil {
Expect(err).To(MatchError(tc.expectError))
}
if tc.expectError == nil {
} else {
Expect(err).To(BeNil())
}
if tc.conditionSet {
Expect(isPresentAndFalseWithReason(tc.hm, infrav1.HetznerAPIReachableCondition, infrav1.RateLimitExceededReason)).To(BeTrue())
Expect(conditions.Has(tc.hm, infrav1.HetznerAPIReachableCondition)).To(BeTrue())
} else {
Expect(isPresentAndFalseWithReason(tc.hm, infrav1.HetznerAPIReachableCondition, infrav1.RateLimitExceededReason)).To(BeFalse())
Expect(conditions.Has(tc.hm, infrav1.HetznerAPIReachableCondition)).To(BeFalse())
}
},
Entry("machine not ready, rate limit exceeded error", testCaseHandleRateLimit{
Expand Down Expand Up @@ -439,13 +433,3 @@ var _ = Describe("Test handleRateLimit", func() {
}),
)
})

// checks whether a condition is Present and is False with a Reason.
func isPresentAndFalseWithReason(getter conditions.Getter, condition clusterv1.ConditionType, reason string) bool {
if !conditions.Has(getter, condition) {
return false
}
objectCondition := conditions.Get(getter, condition)
return objectCondition.Status == corev1.ConditionFalse &&
objectCondition.Reason == reason
}

0 comments on commit 7661ac1

Please sign in to comment.