Browse Source

e2e: created JSONDataWithoutTargetName() test case

Mateus Oliveira Patrício 4 years ago
parent
commit
4c12ce0333
1 changed files with 39 additions and 23 deletions
  1. 39 23
      e2e/suite/common/common.go

+ 39 - 23
e2e/suite/common/common.go

@@ -121,12 +121,12 @@ func JSONDataWithProperty(f *framework.Framework) (string, func(*framework.TestC
 	}
 }
 
-// This case creates multiple secrets with json values and renders a template.
+// This case creates a secret with empty target name to test if it defaults to external secret name.
 // The data is extracted from the JSON key using ref.Property.
-func JSONDataWithTemplate(f *framework.Framework) (string, func(*framework.TestCase)) {
-	return "[common] should sync json secrets with template", func(tc *framework.TestCase) {
+func JSONDataWithoutTargetName(f *framework.Framework) (string, func(*framework.TestCase)) {
+	return "[common] should sync multiple secrets from .Data[]", func(tc *framework.TestCase) {
 		secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
-		secretKey2 := fmt.Sprintf("%s-%s", f.Namespace.Name, "other")
+		secretKey2 := fmt.Sprintf("%s-%s", f.Namespace.Name, "two")
 		secretValue1 := "{\"foo1\":\"foo1-val\",\"bar1\":\"bar1-val\"}"
 		secretValue2 := "{\"foo2\":\"foo2-val\",\"bar2\":\"bar2-val\"}"
 		tc.Secrets = map[string]string{
@@ -135,20 +135,42 @@ func JSONDataWithTemplate(f *framework.Framework) (string, func(*framework.TestC
 		}
 		tc.ExpectedSecret = &v1.Secret{
 			Type: v1.SecretTypeOpaque,
-			ObjectMeta: metav1.ObjectMeta{
-				Annotations: map[string]string{
-					"example": "annotation",
-				},
-				Labels: map[string]string{
-					"example": "label",
+			Data: map[string][]byte{
+				secretKey1: []byte("foo1-val"),
+				secretKey2: []byte("bar2-val"),
+			},
+		}
+		tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
+			{
+				SecretKey: secretKey1,
+				RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
+					Key:      secretKey1,
+					Property: "foo1",
 				},
 			},
-			Data: map[string][]byte{
-				"my-data": []byte(`executed: foo1-val|bar2-val`),
+			{
+				SecretKey: secretKey2,
+				RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
+					Key:      secretKey2,
+					Property: "bar2",
+				},
 			},
 		}
-		tc.ExternalSecret.Spec.Target.Template = &esv1alpha1.ExternalSecretTemplate{
-			Metadata: esv1alpha1.ExternalSecretTemplateMetadata{
+	}
+}
+
+// This case creates multiple secrets with json values and renders a template.
+// The data is extracted from the JSON key using ref.Property.
+func JSONDataWithTemplate(f *framework.Framework) (string, func(*framework.TestCase)) {
+	return "[common] should sync json secrets with template", func(tc *framework.TestCase) {
+		secretKey1 := fmt.Sprintf("%s-%s", f.Namespace.Name, "one")
+		secretValue1 := "{\"foo1\":\"foo1-val\",\"bar1\":\"bar1-val\"}"
+		tc.Secrets = map[string]string{
+			secretKey1: secretValue1,
+		}
+		tc.ExpectedSecret = &v1.Secret{
+			Type: v1.SecretTypeOpaque,
+			ObjectMeta: metav1.ObjectMeta{
 				Annotations: map[string]string{
 					"example": "annotation",
 				},
@@ -156,10 +178,11 @@ func JSONDataWithTemplate(f *framework.Framework) (string, func(*framework.TestC
 					"example": "label",
 				},
 			},
-			Data: map[string]string{
-				"my-data": "executed: {{ .one | toString }}|{{ .two | toString }}",
+			Data: map[string][]byte{
+				"my-data": []byte(`executed: foo1-val`),
 			},
 		}
+		tc.ExternalSecret.Spec.Target.Name = ""
 		tc.ExternalSecret.Spec.Data = []esv1alpha1.ExternalSecretData{
 			{
 				SecretKey: "one",
@@ -168,13 +191,6 @@ func JSONDataWithTemplate(f *framework.Framework) (string, func(*framework.TestC
 					Property: "foo1",
 				},
 			},
-			{
-				SecretKey: "two",
-				RemoteRef: esv1alpha1.ExternalSecretDataRemoteRef{
-					Key:      secretKey2,
-					Property: "bar2",
-				},
-			},
 		}
 	}
 }