1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package manifest_test
16
17 import (
18 "context"
19 "reflect"
20 "strings"
21 "testing"
22
23 corev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/apis/core/v1beta1"
24 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/k8s"
25 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/manifest"
26
27 "github.com/google/go-cmp/cmp"
28 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29 )
30
31 func TestManifestLoader_ResolveManifest(t *testing.T) {
32 t.Parallel()
33 basedir, repo := newTestNewLocalRepository(t)
34 ml := manifest.NewManifestLoader(repo)
35 tests := []struct {
36 name string
37 cc *corev1beta1.ConfigConnector
38 result map[string]string
39 }{
40 {
41 name: "cluster mode, workload identity",
42 cc: &corev1beta1.ConfigConnector{
43 ObjectMeta: metav1.ObjectMeta{
44 Name: k8s.ConfigConnectorAllowedName,
45 },
46 Spec: corev1beta1.ConfigConnectorSpec{
47 GoogleServiceAccount: "foo@bar.iam.gserviceaccount.com",
48 Mode: "cluster",
49 },
50 },
51 result: map[string]string{strings.Join([]string{basedir, "packages", "configconnector", "0.0.0-test", "cluster", "workload-identity"}, "/"): clusterModeWIManifest},
52 },
53 {
54 name: "cluster mode, gcp identity",
55 cc: &corev1beta1.ConfigConnector{
56 ObjectMeta: metav1.ObjectMeta{
57 Name: k8s.ConfigConnectorAllowedName,
58 },
59 Spec: corev1beta1.ConfigConnectorSpec{
60 CredentialSecretName: "my-key",
61 Mode: "cluster",
62 },
63 },
64 result: map[string]string{strings.Join([]string{basedir, "packages", "configconnector", "0.0.0-test", "cluster", "gcp-identity"}, "/"): clusterModeGcpManifest},
65 },
66 {
67 name: "namespaced mode",
68 cc: &corev1beta1.ConfigConnector{
69 ObjectMeta: metav1.ObjectMeta{
70 Name: k8s.ConfigConnectorAllowedName,
71 },
72 Spec: corev1beta1.ConfigConnectorSpec{
73 GoogleServiceAccount: "foo@bar.iam.gserviceaccount.com",
74 Mode: "namespaced",
75 },
76 },
77 result: map[string]string{strings.Join([]string{basedir, "packages", "configconnector", "0.0.0-test", "namespaced"}, "/"): namespacedManifest},
78 },
79 }
80 for _, test := range tests {
81 tc := test
82 t.Run(tc.name, func(t *testing.T) {
83 t.Parallel()
84 manifestStr, err := ml.ResolveManifest(context.TODO(), tc.cc)
85 if err != nil {
86 t.Fatalf("unexpected error while loadding the manifest for namespaced components: %v", err)
87 }
88 if !reflect.DeepEqual(manifestStr, tc.result) {
89 t.Fatalf("unexpected diff: %v", cmp.Diff(manifestStr, tc.result))
90 }
91 })
92 }
93 }
94
View as plain text