Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: nitishfy <[email protected]>
  • Loading branch information
nitishfy committed Nov 22, 2024
1 parent bd02cfa commit 8866c04
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 31 deletions.
40 changes: 38 additions & 2 deletions cmd/argocd/commands/applicationset.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,45 @@ func printAppSetSummaryTable(appSet *arogappsetv1.ApplicationSet) {
} else {
fmt.Println("Sources:")
}
for _, source := range appSet.Spec.Template.Spec.GetSources() {
printAppSourceDetails(&source)

// if no source has been defined, print the default value for a source
if len(appSet.Spec.Template.Spec.GetSources()) == 0 {
src := appSet.Spec.Template.Spec.GetSource()
printAppSourceDetails(&src)
} else {
// otherwise range over the sources and print each source details
for _, source := range appSet.Spec.Template.Spec.GetSources() {
printAppSourceDetails(&source)
}
}

var (
syncPolicyStr string
syncPolicy = appSet.Spec.Template.Spec.SyncPolicy
)
if syncPolicy != nil && syncPolicy.Automated != nil {
syncPolicyStr = "Automated"
if syncPolicy.Automated.Prune {
syncPolicyStr += " (Prune)"
}
} else {
syncPolicyStr = "<none>"
}
fmt.Printf(printOpFmtStr, "SyncPolicy:", syncPolicyStr)
}

func printAppSetSummaryTables(appSet *arogappsetv1.ApplicationSet) {
source := appSet.Spec.Template.Spec.GetSource()
fmt.Printf(printOpFmtStr, "Name:", appSet.QualifiedName())
fmt.Printf(printOpFmtStr, "Project:", appSet.Spec.Template.Spec.GetProject())
fmt.Printf(printOpFmtStr, "Server:", getServerForAppSet(appSet))
fmt.Printf(printOpFmtStr, "Namespace:", appSet.Spec.Template.Spec.Destination.Namespace)
if !appSet.Spec.Template.Spec.HasMultipleSources() {
fmt.Println("Source:")
} else {
fmt.Println("Sources:")
}
printAppSourceDetails(&source)

var (
syncPolicyStr string
Expand Down
58 changes: 29 additions & 29 deletions cmd/argocd/commands/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,73 +194,73 @@ func TestPrintAppSetSummaryTable(t *testing.T) {
expectedOutput string
}{
{
name: "appset with a single source",
appSet: appsetSpecSource,
name: "appset with only spec.syncPolicy set",
appSet: appsetSpecSyncPolicy,
expectedOutput: `Name: app-name
Project: default
Server:
Namespace:
Source:
- Repo: test1
Target: master1
Path: /test1
- Repo:
Target:
SyncPolicy: <none>
`,
},
{
name: "appset with a multiple sources",
appSet: appsetSpecSources,
name: "appset with only spec.template.spec.syncPolicy set",
appSet: appSetTemplateSpecSyncPolicy,
expectedOutput: `Name: app-name
Project: default
Server:
Namespace:
Sources:
- Repo: test1
Target: master1
Path: /test1
- Repo: test2
Target: master2
Path: /test2
SyncPolicy: <none>
Source:
- Repo:
Target:
SyncPolicy: Automated
`,
},
{
name: "appset with only spec.syncPolicy set",
appSet: appsetSpecSyncPolicy,
name: "appset with both spec.SyncPolicy and spec.template.spec.syncPolicy set",
appSet: appSetBothSyncPolicies,
expectedOutput: `Name: app-name
Project: default
Server:
Namespace:
Source:
- Repo:
Target:
SyncPolicy: <none>
SyncPolicy: Automated
`,
},
{
name: "appset with only spec.template.spec.syncPolicy set",
appSet: appSetTemplateSpecSyncPolicy,
name: "appset with a single source",
appSet: appsetSpecSource,
expectedOutput: `Name: app-name
Project: default
Server:
Namespace:
Source:
- Repo:
Target:
SyncPolicy: Automated
- Repo: test1
Target: master1
Path: /test1
SyncPolicy: <none>
`,
},
{
name: "appset with both spec.SyncPolicy and spec.template.spec.syncPolicy set",
appSet: appSetBothSyncPolicies,
name: "appset with a multiple sources",
appSet: appsetSpecSources,
expectedOutput: `Name: app-name
Project: default
Server:
Namespace:
Source:
- Repo:
Target:
SyncPolicy: Automated
Sources:
- Repo: test1
Target: master1
Path: /test1
- Repo: test2
Target: master2
Path: /test2
SyncPolicy: <none>
`,
},
} {
Expand Down

0 comments on commit 8866c04

Please sign in to comment.