Skip to content

Commit

Permalink
tests(konnect): fix flaky KongConsumerCredential tests (#719)
Browse files Browse the repository at this point in the history
* tests(konnect): fix flaky KongConsumerCredential tests

* Update test/envtest/kongconsumercredential_jwt_test.go
  • Loading branch information
pmalek authored Oct 9, 2024
1 parent fc9e3c1 commit efe6637
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/envtest/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package envtest

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func assertCollectObjectExistsAndHasKonnectID(
t *testing.T,
ctx context.Context,
clientNamespaced client.Client,
obj interface {
client.Object
GetKonnectID() string
},
konnectID string,
) func(c *assert.CollectT) {
t.Helper()

return func(c *assert.CollectT) {
nn := client.ObjectKeyFromObject(obj)
if !assert.NoError(c, clientNamespaced.Get(ctx, nn, obj)) {
return
}
assert.Equal(t, konnectID, obj.GetKonnectID())
}
}
6 changes: 6 additions & 0 deletions test/envtest/kongconsumercredential_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ func TestKongConsumerCredential_ACL(t *testing.T) {

StartReconcilers(ctx, t, mgr, logs, reconcilers...)

assert.EventuallyWithT(t,
assertCollectObjectExistsAndHasKonnectID(t, ctx, clientNamespaced, kongCredentialACL, aclID),
waitTime, tickTime,
"KongCredentialACL wasn't created",
)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(c, factory.SDK.KongCredentialsACLSDK.AssertExpectations(t))
}, waitTime, tickTime)
Expand Down
6 changes: 6 additions & 0 deletions test/envtest/kongconsumercredential_apikey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func TestKongConsumerCredential_APIKey(t *testing.T) {

StartReconcilers(ctx, t, mgr, logs, reconcilers...)

assert.EventuallyWithT(t,
assertCollectObjectExistsAndHasKonnectID(t, ctx, clientNamespaced, kongCredentialAPIKey, keyID),
waitTime, tickTime,
"KongCredentialAPIKey wasn't created",
)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(c, factory.SDK.KongCredentialsAPIKeySDK.AssertExpectations(t))
}, waitTime, tickTime)
Expand Down
6 changes: 6 additions & 0 deletions test/envtest/kongconsumercredential_basicauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func TestKongConsumerCredential_BasicAuth(t *testing.T) {

StartReconcilers(ctx, t, mgr, logs, reconcilers...)

assert.EventuallyWithT(t,
assertCollectObjectExistsAndHasKonnectID(t, ctx, clientNamespaced, kongCredentialBasicAuth, basicAuthID),
waitTime, tickTime,
"KongCredentialBasicAuth wasn't created",
)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(c, factory.SDK.KongCredentialsBasicAuthSDK.AssertExpectations(t))
}, waitTime, tickTime)
Expand Down
6 changes: 6 additions & 0 deletions test/envtest/kongconsumercredential_hmac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func TestKongConsumerCredential_HMAC(t *testing.T) {

StartReconcilers(ctx, t, mgr, logs, reconcilers...)

assert.EventuallyWithT(t,
assertCollectObjectExistsAndHasKonnectID(t, ctx, clientNamespaced, kongCredentialHMAC, hmacID),
waitTime, tickTime,
"KongCredentialHMAC wasn't created",
)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(c, factory.SDK.KongCredentialsHMACSDK.AssertExpectations(t))
}, waitTime, tickTime)
Expand Down
6 changes: 6 additions & 0 deletions test/envtest/kongconsumercredential_jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ func TestKongConsumerCredential_JWT(t *testing.T) {

StartReconcilers(ctx, t, mgr, logs, reconcilers...)

assert.EventuallyWithT(t,
assertCollectObjectExistsAndHasKonnectID(t, ctx, clientNamespaced, kongCredentialJWT, jwtID),
waitTime, tickTime,
"KongCredentialJWT wasn't created",
)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.True(c, factory.SDK.KongCredentialsJWTSDK.AssertExpectations(t))
}, waitTime, tickTime)
Expand Down

0 comments on commit efe6637

Please sign in to comment.