@@ -11,8 +11,7 @@ import (
11
11
"github.com/stretchr/testify/assert"
12
12
"github.com/stretchr/testify/mock"
13
13
"github.com/stretchr/testify/require"
14
- corev1 "k8s.io/api/core/v1"
15
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
+ "k8s.io/apimachinery/pkg/watch"
16
15
"sigs.k8s.io/controller-runtime/pkg/client"
17
16
18
17
"github.com/kong/gateway-operator/controller/konnect"
@@ -35,6 +34,10 @@ func TestKongConsumerCredential_BasicAuth(t *testing.T) {
35
34
36
35
mgr , logs := NewManager (t , ctx , cfg , scheme .Get ())
37
36
37
+ clientWithWatch , err := client .NewWithWatch (mgr .GetConfig (), client.Options {
38
+ Scheme : scheme .Get (),
39
+ })
40
+ require .NoError (t , err )
38
41
clientNamespaced := client .NewNamespacedClient (mgr .GetClient (), ns .Name )
39
42
40
43
apiAuth := deployKonnectAPIAuthConfigurationWithProgrammed (t , ctx , clientNamespaced )
@@ -64,23 +67,7 @@ func TestKongConsumerCredential_BasicAuth(t *testing.T) {
64
67
65
68
password := "password"
66
69
username := "username"
67
- credentialBasicAuth := & configurationv1alpha1.CredentialBasicAuth {
68
- ObjectMeta : metav1.ObjectMeta {
69
- GenerateName : "basic-auth-" ,
70
- },
71
- Spec : configurationv1alpha1.CredentialBasicAuthSpec {
72
- ConsumerRef : corev1.LocalObjectReference {
73
- Name : consumer .Name ,
74
- },
75
- CredentialBasicAuthAPISpec : configurationv1alpha1.CredentialBasicAuthAPISpec {
76
- Password : password ,
77
- Username : username ,
78
- },
79
- },
80
- }
81
- require .NoError (t , clientNamespaced .Create (ctx , credentialBasicAuth ))
82
- t .Logf ("deployed %s CredentialBasicAuth resource" , client .ObjectKeyFromObject (credentialBasicAuth ))
83
-
70
+ credentialBasicAuth := deployCredentialBasicAuth (t , ctx , clientNamespaced , consumer .Name , username , password )
84
71
basicAuthID := uuid .NewString ()
85
72
tags := []string {
86
73
"k8s-generation:1" ,
@@ -158,4 +145,21 @@ func TestKongConsumerCredential_BasicAuth(t *testing.T) {
158
145
assert .EventuallyWithT (t , func (c * assert.CollectT ) {
159
146
assert .True (c , factory .SDK .BasicAuthCredentials .AssertExpectations (t ))
160
147
}, waitTime , tickTime )
148
+
149
+ w := setupWatch [configurationv1alpha1.CredentialBasicAuthList ](t , ctx , clientWithWatch , client .InNamespace (ns .Name ))
150
+
151
+ credentialBasicAuth = deployCredentialBasicAuth (t , ctx , clientNamespaced , consumer .Name , username , password )
152
+ t .Logf ("redeployed %s CredentialBasicAuth resource" , client .ObjectKeyFromObject (credentialBasicAuth ))
153
+ t .Logf ("checking if KongConsumer %s removal will delete the associated credentials %s" ,
154
+ client .ObjectKeyFromObject (consumer ),
155
+ client .ObjectKeyFromObject (credentialBasicAuth ),
156
+ )
157
+
158
+ require .NoError (t , clientNamespaced .Delete (ctx , consumer ))
159
+ _ = watchFor (t , ctx , w , watch .Modified ,
160
+ func (c * configurationv1alpha1.CredentialBasicAuth ) bool {
161
+ return c .Name == credentialBasicAuth .Name
162
+ },
163
+ "CredentialBasicAuth wasn't deleted but it should have been" ,
164
+ )
161
165
}
0 commit comments