@@ -16,6 +16,7 @@ import (
1616
1717 "github.com/openshift/external-secrets-operator/api/v1alpha1"
1818 "github.com/openshift/external-secrets-operator/pkg/controller/client/fakes"
19+ "github.com/openshift/external-secrets-operator/pkg/controller/commontest"
1920)
2021
2122var (
@@ -86,22 +87,22 @@ func TestCreateOrApplyCertificates(t *testing.T) {
8687 es .Spec .ExternalSecretsConfig .WebhookConfig .CertManagerConfig .IssuerRef .Name = ""
8788 },
8889 recon : false ,
89- wantErr : fmt .Sprintf ("failed to update certificate resource for %s/%s deployment: issuerRef.Name not present" , testNamespace , testExternalSecretsForCertificate ().GetName ()),
90+ wantErr : fmt .Sprintf ("failed to update certificate resource for %s/%s deployment: issuerRef.Name not present" , commontest . TestExternalSecretsNamespace , testExternalSecretsForCertificate ().GetName ()),
9091 },
9192 {
9293 name : "reconciliation of webhook certificate fails while checking if exists" ,
9394 preReq : func (r * Reconciler , m * fakes.FakeCtrlClient ) {
9495 m .ExistsCalls (func (ctx context.Context , ns types.NamespacedName , obj client.Object ) (bool , error ) {
9596 if ns .Name == serviceExternalSecretWebhookName {
96- return false , testError
97+ return false , commontest . TestClientError
9798 }
9899 if ns .Name == "test-issuer" {
99100 return true , nil
100101 }
101102 return false , nil
102103 })
103104 m .GetCalls (func (ctx context.Context , ns types.NamespacedName , obj client.Object ) error {
104- if ns .Name == "test-issuer" && ns .Namespace == testNamespace {
105+ if ns .Name == "test-issuer" && ns .Namespace == commontest . TestExternalSecretsNamespace {
105106 if u , ok := obj .(* unstructured.Unstructured ); ok {
106107 issuer := testIssuer ()
107108 unstructuredIssuer , err := runtime .DefaultUnstructuredConverter .ToUnstructured (issuer )
@@ -124,7 +125,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
124125 es .Spec .ExternalSecretsConfig .WebhookConfig .CertManagerConfig .IssuerRef .Name = "test-issuer"
125126 },
126127 recon : false ,
127- wantErr : fmt .Sprintf ("failed to check %s/%s certificate resource already exists: %s" , testNamespace , testValidateCertificateResourceName , testError ),
128+ wantErr : fmt .Sprintf ("failed to check %s/%s certificate resource already exists: %s" , commontest . TestExternalSecretsNamespace , testValidateCertificateResourceName , commontest . TestClientError ),
128129 },
129130 {
130131 name : "reconciliation of webhook certificate fails while restoring to expected state" ,
@@ -133,7 +134,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
133134 switch o := obj .(type ) {
134135 case * certmanagerv1.Certificate :
135136 if ns .Name == serviceExternalSecretWebhookName {
136- cert := testCertificate ()
137+ cert := testCertificate (webhookCertificateAssetName )
137138 cert .SetLabels (map [string ]string {"different" : "labels" })
138139 cert .DeepCopyInto (o )
139140 return nil
@@ -167,7 +168,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
167168 })
168169 m .UpdateWithRetryCalls (func (ctx context.Context , obj client.Object , opts ... client.UpdateOption ) error {
169170 if obj .GetName () == serviceExternalSecretWebhookName {
170- return testError
171+ return commontest . TestClientError
171172 }
172173 return nil
173174 })
@@ -177,7 +178,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
177178 es .Spec .ExternalSecretsConfig .WebhookConfig .CertManagerConfig .IssuerRef .Name = "test-issuer"
178179 },
179180 recon : false ,
180- wantErr : fmt .Sprintf ("failed to update %s/%s certificate resource: %s" , testNamespace , testValidateCertificateResourceName , testError ),
181+ wantErr : fmt .Sprintf ("failed to update %s/%s certificate resource: %s" , commontest . TestExternalSecretsNamespace , testValidateCertificateResourceName , commontest . TestClientError ),
181182 },
182183 {
183184 name : "reconciliation of webhook certificate which already exists in expected state" ,
@@ -247,12 +248,12 @@ func TestCreateOrApplyCertificates(t *testing.T) {
247248 })
248249 m .CreateCalls (func (ctx context.Context , obj client.Object , opts ... client.CreateOption ) error {
249250 if obj .GetName () == serviceExternalSecretWebhookName {
250- return testError
251+ return commontest . TestClientError
251252 }
252253 return nil
253254 })
254255 m .GetCalls (func (ctx context.Context , ns types.NamespacedName , obj client.Object ) error {
255- if ns .Name == "test-issuer" && ns .Namespace == testNamespace {
256+ if ns .Name == "test-issuer" && ns .Namespace == commontest . TestExternalSecretsNamespace {
256257 testIssuer ().DeepCopyInto (obj .(* certmanagerv1.Issuer ))
257258 return nil
258259 }
@@ -264,7 +265,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
264265 es .Spec .ExternalSecretsConfig .WebhookConfig .CertManagerConfig .IssuerRef .Name = "test-issuer"
265266 },
266267 recon : false ,
267- wantErr : fmt .Sprintf ("failed to create %s/%s certificate resource: %s" , testNamespace , testValidateCertificateResourceName , testError ),
268+ wantErr : fmt .Sprintf ("failed to create %s/%s certificate resource: %s" , commontest . TestExternalSecretsNamespace , testValidateCertificateResourceName , commontest . TestClientError ),
268269 },
269270 {
270271 name : "successful webhook certificate creation" ,
@@ -286,7 +287,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
286287 return nil
287288 })
288289 m .GetCalls (func (ctx context.Context , ns types.NamespacedName , obj client.Object ) error {
289- if ns .Name == "test-issuer" && ns .Namespace == testNamespace {
290+ if ns .Name == "test-issuer" && ns .Namespace == commontest . TestExternalSecretsNamespace {
290291 testIssuer ().DeepCopyInto (obj .(* certmanagerv1.Issuer ))
291292 return nil
292293 }
@@ -318,12 +319,12 @@ func TestCreateOrApplyCertificates(t *testing.T) {
318319 m .GetCalls (func (ctx context.Context , ns types.NamespacedName , obj client.Object ) error {
319320 switch o := obj .(type ) {
320321 case * corev1.Secret :
321- if ns .Name == "bitwarden-secret" && ns .Namespace == testNamespace {
322+ if ns .Name == "bitwarden-secret" && ns .Namespace == commontest . TestExternalSecretsNamespace {
322323 testSecretForCertificate ().DeepCopyInto (o )
323324 return nil
324325 }
325326 case * certmanagerv1.Issuer :
326- if ns .Name == "test-issuer" && ns .Namespace == testNamespace {
327+ if ns .Name == "test-issuer" && ns .Namespace == commontest . TestExternalSecretsNamespace {
327328 testIssuer ().DeepCopyInto (o )
328329 return nil
329330 }
@@ -371,11 +372,11 @@ func TestCreateOrApplyCertificates(t *testing.T) {
371372 m .GetCalls (func (ctx context.Context , ns types.NamespacedName , obj client.Object ) error {
372373 switch o := obj .(type ) {
373374 case * corev1.Secret :
374- if ns .Name == "bitwarden-secret" && ns .Namespace == testNamespace {
375- return testError
375+ if ns .Name == "bitwarden-secret" && ns .Namespace == commontest . TestExternalSecretsNamespace {
376+ return commontest . TestClientError
376377 }
377378 case * certmanagerv1.Issuer :
378- if ns .Name == "test-issuer" && ns .Namespace == testNamespace {
379+ if ns .Name == "test-issuer" && ns .Namespace == commontest . TestExternalSecretsNamespace {
379380 testIssuer ().DeepCopyInto (o )
380381 return nil
381382 }
@@ -398,7 +399,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
398399 }
399400 },
400401 recon : false ,
401- wantErr : fmt .Sprintf ("failed to fetch %q secret: %s" , types.NamespacedName {Name : "bitwarden-secret" , Namespace : testNamespace }, testError ),
402+ wantErr : fmt .Sprintf ("failed to fetch %q secret: %s" , types.NamespacedName {Name : "bitwarden-secret" , Namespace : commontest . TestExternalSecretsNamespace }, commontest . TestClientError ),
402403 },
403404 {
404405 name : "bitwarden disabled (explicitly nil): only webhook certificate reconciled" ,
@@ -427,7 +428,7 @@ func TestCreateOrApplyCertificates(t *testing.T) {
427428 return nil
428429 })
429430 m .GetCalls (func (ctx context.Context , ns types.NamespacedName , obj client.Object ) error {
430- if ns .Name == "test-issuer" && ns .Namespace == testNamespace {
431+ if ns .Name == "test-issuer" && ns .Namespace == commontest . TestExternalSecretsNamespace {
431432 testIssuer ().DeepCopyInto (obj .(* certmanagerv1.Issuer ))
432433 return nil
433434 }
@@ -466,11 +467,11 @@ func TestCreateOrApplyCertificates(t *testing.T) {
466467}
467468
468469func testExternalSecretsForCertificate () * v1alpha1.ExternalSecrets {
469- externalSecrets := testExternalSecrets ()
470+ externalSecrets := commontest . TestExternalSecrets ()
470471
471472 externalSecrets .Spec = v1alpha1.ExternalSecretsSpec {
472473 ControllerConfig : & v1alpha1.ControllerConfig {
473- Namespace : testNamespace ,
474+ Namespace : commontest . TestExternalSecretsNamespace ,
474475 },
475476 ExternalSecretsConfig : & v1alpha1.ExternalSecretsConfig {
476477 WebhookConfig : & v1alpha1.WebhookConfig {
@@ -489,7 +490,7 @@ func testIssuer() *certmanagerv1.Issuer {
489490 return & certmanagerv1.Issuer {
490491 ObjectMeta : metav1.ObjectMeta {
491492 Name : "test-issuer" ,
492- Namespace : testNamespace ,
493+ Namespace : commontest . TestExternalSecretsNamespace ,
493494 },
494495 Spec : certmanagerv1.IssuerSpec {
495496 IssuerConfig : certmanagerv1.IssuerConfig {
@@ -517,7 +518,7 @@ func testSecretForCertificate() *corev1.Secret {
517518 return & corev1.Secret {
518519 ObjectMeta : metav1.ObjectMeta {
519520 Name : "bitwarden-secret" ,
520- Namespace : testNamespace ,
521+ Namespace : commontest . TestExternalSecretsNamespace ,
521522 },
522523 Data : map [string ][]byte {
523524 "username" : []byte ("testuser" ),
0 commit comments