@@ -93,3 +93,52 @@ func TestGenerator_WriteFile(t *testing.T) {
93
93
})
94
94
}
95
95
}
96
+
97
+ func TestGenerator_Components (t * testing.T ) {
98
+ tests := []struct {
99
+ name string
100
+ dir string
101
+ fluxComponents []string
102
+ expectedComponents []string
103
+ }{
104
+ {
105
+ name : "test kustomization.yaml with components and Flux Kustomization without components" ,
106
+ dir : "components" ,
107
+ fluxComponents : []string {},
108
+ expectedComponents : []string {"componentA" },
109
+ },
110
+ {
111
+ name : "test kustomization.yaml without components and Flux Kustomization with components" ,
112
+ dir : "zero-components" ,
113
+ fluxComponents : []string {"componentB" , "componentC" },
114
+ expectedComponents : []string {"componentB" , "componentC" },
115
+ },
116
+ {
117
+ name : "test kustomization.yaml with components and Flux Kustomization with components" ,
118
+ dir : "components" ,
119
+ fluxComponents : []string {"componentB" , "componentC" },
120
+ expectedComponents : []string {"componentA" , "componentB" , "componentC" },
121
+ },
122
+ }
123
+
124
+ for _ , tt := range tests {
125
+ t .Run (tt .name , func (t * testing.T ) {
126
+ g := NewWithT (t )
127
+ tmpDir := t .TempDir ()
128
+ g .Expect (copy .Copy ("./testdata/components" , tmpDir )).To (Succeed ())
129
+ ks := v1beta2.Kustomization {
130
+ Spec : v1beta2.KustomizationSpec {
131
+ Components : tt .fluxComponents ,
132
+ },
133
+ }
134
+ kfile , err := NewGenerator (filepath .Join (tmpDir , tt .dir ), & ks ).WriteFile (filepath .Join (tmpDir , tt .dir ))
135
+ g .Expect (err ).ToNot (HaveOccurred ())
136
+
137
+ kfileYAML , err := os .ReadFile (kfile )
138
+ g .Expect (err ).ToNot (HaveOccurred ())
139
+ var k kustypes.Kustomization
140
+ g .Expect (k .Unmarshal (kfileYAML )).To (Succeed ())
141
+ g .Expect (k .Components ).Should (Equal (tt .expectedComponents ))
142
+ })
143
+ }
144
+ }
0 commit comments