Skip to content

Commit

Permalink
upadte unit test to ahve both Source and Sources and update function …
Browse files Browse the repository at this point in the history
…to overlooked source if sources is persent

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
  • Loading branch information
Mangaal committed Mar 15, 2024
1 parent 485329f commit 5ffcb73
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 11 deletions.
22 changes: 11 additions & 11 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2470,17 +2470,7 @@ func printApplicationHistoryTable(revHistory []argoappv1.RevisionHistory) {
}
varHistory := map[string][]history{}
for _, depInfo := range revHistory {
if depInfo.Source.RepoURL != "" {
rev := depInfo.Source.TargetRevision
if len(depInfo.Revision) >= 7 {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revision[0:7])
}
varHistory[depInfo.Source.RepoURL] = append(varHistory[depInfo.Source.RepoURL], history{
id: depInfo.ID,
date: depInfo.DeployedAt.String(),
revision: rev,
})
}

if depInfo.Sources != nil {
for i, sourceInfo := range depInfo.Sources {
rev := sourceInfo.TargetRevision
Expand All @@ -2493,6 +2483,16 @@ func printApplicationHistoryTable(revHistory []argoappv1.RevisionHistory) {
revision: rev,
})
}
} else {
rev := depInfo.Source.TargetRevision
if len(depInfo.Revision) >= 7 {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revision[0:7])
}
varHistory[depInfo.Source.RepoURL] = append(varHistory[depInfo.Source.RepoURL], history{
id: depInfo.ID,
date: depInfo.DeployedAt.String(),
revision: rev,
})
}
}
for source, historyEntries := range varHistory {
Expand Down
80 changes: 80 additions & 0 deletions cmd/argocd/commands/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,86 @@ func TestPrintApplicationHistoryTable(t *testing.T) {
func TestPrintApplicationHistoryTableWithMultipleSources(t *testing.T) {
histories := []v1alpha1.RevisionHistory{
{
ID: 0,
Source: v1alpha1.ApplicationSource{
TargetRevision: "0",
RepoURL: "test",
},
},
{
ID: 1,
Revisions: []string{
"1a",
"1b",
},
//added Source just for testing the fuction
Source: v1alpha1.ApplicationSource{
TargetRevision: "-1",
RepoURL: "ignore",
},
Sources: v1alpha1.ApplicationSources{
v1alpha1.ApplicationSource{
RepoURL: "test-1",
TargetRevision: "1a",
},
v1alpha1.ApplicationSource{
RepoURL: "test-2",
TargetRevision: "1b",
},
},
},
{
ID: 2,
Revisions: []string{
"2a",
"2b",
},
Sources: v1alpha1.ApplicationSources{
v1alpha1.ApplicationSource{
RepoURL: "test-1",
TargetRevision: "2a",
},
v1alpha1.ApplicationSource{
RepoURL: "test-2",
TargetRevision: "2b",
},
},
},
{
ID: 3,
Revisions: []string{
"3a",
"3b",
},
Sources: v1alpha1.ApplicationSources{
v1alpha1.ApplicationSource{
RepoURL: "test-1",
TargetRevision: "3a",
},
v1alpha1.ApplicationSource{
RepoURL: "test-2",
TargetRevision: "3b",
},
},
},
}

output, _ := captureOutput(func() error {
printApplicationHistoryTable(histories)
return nil
})

expectation := "\nSOURCE test\nID DATE REVISION\n0 0001-01-01 00:00:00 +0000 UTC 0\n\nSOURCE test-1\nID DATE REVISION\n1 0001-01-01 00:00:00 +0000 UTC 1a\n2 0001-01-01 00:00:00 +0000 UTC 2a\n3 0001-01-01 00:00:00 +0000 UTC 3a\n\nSOURCE test-2\nID DATE REVISION\n1 0001-01-01 00:00:00 +0000 UTC 1b\n2 0001-01-01 00:00:00 +0000 UTC 2b\n3 0001-01-01 00:00:00 +0000 UTC 3b\n"

if output != expectation {
t.Fatalf("Incorrect print operation output %q, should be %q", output, expectation)
}
}

func TestPrintApplicationHistoryTableForWhenBothSourcesAndSourceFiledsExist(t *testing.T) {
histories := []v1alpha1.RevisionHistory{
{

ID: 1,
Revisions: []string{
"1a",
Expand Down

0 comments on commit 5ffcb73

Please sign in to comment.