Skip to content

Commit

Permalink
Support multiple commands for custom synchers
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Oct 25, 2023
1 parent c0134ce commit 1a1fb1d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
33 changes: 22 additions & 11 deletions synchers/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,34 @@ func (root CustomSyncRoot) GetPrerequisiteCommand(environment Environment, comma
func (root CustomSyncRoot) GetRemoteCommand(sourceEnvironment Environment) []SyncCommand {

transferResource := root.GetTransferResource(sourceEnvironment)
return []SyncCommand{{
command: fmt.Sprintf(root.Source.Commands[0]),
substitutions: map[string]interface{}{
"transferResource": transferResource.Name,
},
},

ret := []SyncCommand{}

substitutions := map[string]interface{}{
"transferResource": transferResource.Name,
}

for _, c := range root.Source.Commands {
ret = append(ret, generateSyncCommand(c, substitutions))
}

return ret
}

func (m CustomSyncRoot) GetLocalCommand(targetEnvironment Environment) []SyncCommand {
transferResource := m.GetTransferResource(targetEnvironment)
return []SyncCommand{
generateSyncCommand(m.Target.Commands[0],
map[string]interface{}{
"transferResource": transferResource.Name,
}),

ret := []SyncCommand{}

substitutions := map[string]interface{}{
"transferResource": transferResource.Name,
}

for _, c := range m.Target.Commands {
ret = append(ret, generateSyncCommand(c, substitutions))
}

return ret
}

func (m CustomSyncRoot) GetFilesToCleanup(environment Environment) []string {
Expand Down
23 changes: 23 additions & 0 deletions synchers/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ func TestGetCustomSync(t *testing.T) {
Target: BaseCustomSyncCommands{Commands: []string{"second"}},
},
},
{
name: "simple unmarshalling with multiple commands",
//fields: fields{isConfigEmpty: false},
args: args{
syncerName: "customroot",
configRoot: SyncherConfigRoot{
Project: "",
LagoonSync: map[string]interface{}{
"customroot": CustomSyncRoot{
TransferResource: "testing",
Source: BaseCustomSyncCommands{Commands: []string{"first of one", "second of one"}},
Target: BaseCustomSyncCommands{Commands: []string{"first of two", "second of two"}},
},
},
Prerequisites: nil,
},
},
want: CustomSyncRoot{
TransferResource: "testing",
Source: BaseCustomSyncCommands{Commands: []string{"first of one", "second of one"}},
Target: BaseCustomSyncCommands{Commands: []string{"first of two", "second of two"}},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 1a1fb1d

Please sign in to comment.