Browse Source

test: create e2e test to SyncWithoutTargetName

Mateus Oliveira Patrício 4 years ago
parent
commit
5284aca883
2 changed files with 32 additions and 1 deletions
  1. 6 1
      e2e/framework/testcase.go
  2. 26 0
      e2e/suite/common/common.go

+ 6 - 1
e2e/framework/testcase.go

@@ -24,7 +24,7 @@ import (
 	esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
 )
 
-const TargetSecretName = "target-secret"
+var TargetSecretName = "target-secret"
 
 // TestCase contains the test infra to run a table driven test.
 type TestCase struct {
@@ -66,6 +66,11 @@ func TableFunc(f *Framework, prov SecretStoreProvider) func(...func(*TestCase))
 		err = tc.Framework.CRClient.Create(context.Background(), tc.ExternalSecret)
 		Expect(err).ToNot(HaveOccurred())
 
+		// in case target name is empty
+		if tc.ExternalSecret.Spec.Target.Name == "" {
+			TargetSecretName = tc.ExternalSecret.ObjectMeta.Name
+		}
+
 		// wait for Kind=Secret to have the expected data
 		_, err = tc.Framework.WaitForSecretValue(tc.Framework.Namespace.Name, TargetSecretName, tc.ExpectedSecret)
 		Expect(err).ToNot(HaveOccurred())

+ 26 - 0
e2e/suite/common/common.go

@@ -57,6 +57,32 @@ func SimpleDataSync(f *framework.Framework) (string, func(*framework.TestCase))
 	}
 }
 
+// This case creates a secret with empty target name to test if it defaults to external secret name.
+func SyncWithoutTargetName(f *framework.Framework) (string, func(*framework.TestCase)) {
+	return "[common] should sync simple secrets from .Data[]", func(tc *framework.TestCase) {
+		secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
+		secretValue := "bar"
+		tc.Secrets = map[string]string{
+			secretKey1: secretValue,
+		}
+		tc.ExpectedSecret = &v1.Secret{
+			Type: v1.SecretTypeOpaque,
+			Data: map[string][]byte{
+				secretKey1: []byte(secretValue),
+			},
+		}
+		tc.ExternalSecret.Spec.Target.Name = ""
+		tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
+			{
+				SecretKey: secretKey1,
+				RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
+					Key: secretKey1,
+				},
+			},
+		}
+	}
+}
+
 // This case creates multiple secrets with json values and syncs them using multiple .Spec.Data blocks.
 // The data is extracted from the JSON key using ref.Property.
 func JSONDataWithProperty(f *framework.Framework) (string, func(*framework.TestCase)) {