@@ -165,6 +165,81 @@ env: production
165165a: override
166166c:
167167 d: e
168+ ` ))
169+ },
170+ },
171+ {
172+ name : "merge YAML in dirs successfully" ,
173+ setupFunc : func (t * testing.T ) (* swapi.OutputArtifact , map [string ]string , string ) {
174+ tmpDir := t .TempDir ()
175+ source1Dir := filepath .Join (tmpDir , "source1" )
176+ source2Dir := filepath .Join (tmpDir , "source2" )
177+ workspaceDir := filepath .Join (tmpDir , "workspace" )
178+
179+ setupDirs (t , source1Dir , source2Dir , workspaceDir )
180+
181+ // Create first source with base config
182+ createFile (t , source1Dir , "config1.yaml" , `
183+ env: dev
184+ region: us-west-1
185+ ` )
186+ createFile (t , source1Dir , "config2.yaml" , `
187+ version: 1.0.0
188+ image: my-app:latest
189+ ` )
190+
191+ // Create second source with overlay config
192+ createFile (t , source2Dir , "config1.yaml" , "env: prod" ) // This should overwrite the env
193+ createFile (t , source2Dir , "config2.yaml" , "replicas: 5" ) // This should add a new field
194+
195+ spec := & swapi.OutputArtifact {
196+ Name : "yaml-to-yaml-dir-merge" ,
197+ Copy : []swapi.CopyOperation {
198+ {
199+ From : "@source1/**" ,
200+ To : "@artifact/" ,
201+ Strategy : swapi .OverwriteStrategy ,
202+ },
203+ {
204+ From : "@source2/**" ,
205+ To : "@artifact/" ,
206+ Strategy : swapi .MergeStrategy ,
207+ },
208+ },
209+ }
210+
211+ sources := map [string ]string {
212+ "source1" : source1Dir ,
213+ "source2" : source2Dir ,
214+ }
215+ return spec , sources , workspaceDir
216+ },
217+ validateFunc : func (t * testing.T , artifact * gotkmeta.Artifact , workspaceDir string ) {
218+ g := NewWithT (t )
219+ g .Expect (artifact ).ToNot (BeNil ())
220+
221+ // Read the merged config from staging directory
222+ stagingDir := filepath .Join (workspaceDir , "yaml-to-yaml-dir-merge" )
223+ config1Path := filepath .Join (stagingDir , "config1.yaml" )
224+ config2Path := filepath .Join (stagingDir , "config2.yaml" )
225+
226+ config1Content , err := os .ReadFile (config1Path )
227+ g .Expect (err ).ToNot (HaveOccurred ())
228+ g .Expect (config1Content ).ToNot (BeEmpty ())
229+
230+ config2Content , err := os .ReadFile (config2Path )
231+ g .Expect (err ).ToNot (HaveOccurred ())
232+ g .Expect (config2Content ).ToNot (BeEmpty ())
233+
234+ // Verify the merged YAML contains expected content
235+ g .Expect (config1Content ).To (MatchYAML (`
236+ env: prod
237+ region: us-west-1
238+ ` ))
239+ g .Expect (config2Content ).To (MatchYAML (`
240+ image: my-app:latest
241+ replicas: 5
242+ version: 1.0.0
168243` ))
169244 },
170245 },
0 commit comments