@@ -184,6 +184,51 @@ nested:
184184 require .Equal (t , []interface {}{"--no-privileges" , "--no-owner" }, itemsVal )
185185}
186186
187+ func TestStoreYaml_MergeKeyCreatesDirect (t * testing.T ) {
188+ type mergeStruct struct {
189+ Configs map [string ]interface {} `proj:"parent.options.configs,createKey"`
190+ ParallelJobs * int64 `proj:"parent.options.parallelJobs"`
191+ }
192+
193+ const yamlData = `
194+ defaults: &defaults
195+ configs:
196+ shared_buffers: 1GB
197+ work_mem: 100MB
198+
199+ parent:
200+ options:
201+ <<: *defaults
202+ parallelJobs: 4
203+ `
204+
205+ node := & yaml.Node {}
206+ err := yaml .Unmarshal ([]byte (yamlData ), node )
207+ require .NoError (t , err )
208+
209+ pj := int64 (8 )
210+ s := & mergeStruct {Configs : map [string ]interface {}{"fsync" : "off" , "maintenance_work_mem" : "8GB" }, ParallelJobs : & pj }
211+
212+ err = StoreYaml (s , node , StoreOptions {})
213+ require .NoError (t , err )
214+
215+ soft , err := NewSoftYaml (node )
216+ require .NoError (t , err )
217+
218+ configVal , err := soft .Get (FieldGet {Path : []string {"parent" , "options" , "configs" }, Type : ptypes .Map })
219+ require .NoError (t , err )
220+ require .Equal (t , map [string ]interface {}{"fsync" : "off" , "maintenance_work_mem" : "8GB" }, configVal )
221+
222+ pjVal , err := soft .Get (FieldGet {Path : []string {"parent" , "options" , "parallelJobs" }, Type : ptypes .Int64 })
223+ require .NoError (t , err )
224+ require .Equal (t , int64 (8 ), pjVal )
225+
226+ // verify anchor source was not modified
227+ defaultConfigs , err := soft .Get (FieldGet {Path : []string {"defaults" , "configs" }, Type : ptypes .Map })
228+ require .NoError (t , err )
229+ require .Equal (t , map [string ]interface {}{"shared_buffers" : "1GB" , "work_mem" : "100MB" }, defaultConfigs )
230+ }
231+
187232func TestStoreYaml_NilMapPreservesExisting (t * testing.T ) {
188233 type mapStruct struct {
189234 Name * string `proj:"nested.name"`
0 commit comments