Skip to content

Commit

Permalink
fix: flaky test - app history command not printing source in consiste…
Browse files Browse the repository at this point in the history
…nt order (argoproj#17615)

* instead if ranging over the map varHistory to print the history, inroduced a string array varHistoryKeys

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

* update unit test expectation, remove new line in the beginning

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>

---------

Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
Signed-off-by: Kevin Lyda <kevin@lyda.ie>
  • Loading branch information
Mangaal authored and lyda committed Mar 28, 2024
1 parent f942963 commit b6a0273
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2516,14 +2516,17 @@ func printApplicationHistoryTable(revHistory []argoappv1.RevisionHistory) {
revision string
}
varHistory := map[string][]history{}
varHistoryKeys := []string{}
for _, depInfo := range revHistory {

if depInfo.Sources != nil {
for i, sourceInfo := range depInfo.Sources {
rev := sourceInfo.TargetRevision
if len(depInfo.Revisions) == len(depInfo.Sources) && len(depInfo.Revisions[i]) >= MAX_ALLOWED_REVISIONS {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revisions[i][0:MAX_ALLOWED_REVISIONS])
}
if _, ok := varHistory[sourceInfo.RepoURL]; !ok {
varHistoryKeys = append(varHistoryKeys, sourceInfo.RepoURL)
}
varHistory[sourceInfo.RepoURL] = append(varHistory[sourceInfo.RepoURL], history{
id: depInfo.ID,
date: depInfo.DeployedAt.String(),
Expand All @@ -2535,19 +2538,26 @@ func printApplicationHistoryTable(revHistory []argoappv1.RevisionHistory) {
if len(depInfo.Revision) >= MAX_ALLOWED_REVISIONS {
rev = fmt.Sprintf("%s (%s)", rev, depInfo.Revision[0:MAX_ALLOWED_REVISIONS])
}
if _, ok := varHistory[depInfo.Source.RepoURL]; !ok {
varHistoryKeys = append(varHistoryKeys, depInfo.Source.RepoURL)
}
varHistory[depInfo.Source.RepoURL] = append(varHistory[depInfo.Source.RepoURL], history{
id: depInfo.ID,
date: depInfo.DeployedAt.String(),
revision: rev,
})
}
}
for source, historyEntries := range varHistory {
_, _ = fmt.Fprintf(w, "\nSOURCE\t%s\n", source)
for i, key := range varHistoryKeys {
_, _ = fmt.Fprintf(w, "SOURCE\t%s\n", key)
_, _ = fmt.Fprintf(w, "ID\tDATE\tREVISION\n")
for _, history := range historyEntries {
for _, history := range varHistory[key] {
_, _ = fmt.Fprintf(w, "%d\t%s\t%s\n", history.id, history.date, history.revision)
}
// Add a newline if it's not the last iteration
if i < len(varHistoryKeys)-1 {
_, _ = fmt.Fprintf(w, "\n")
}
}
_ = w.Flush()
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/argocd/commands/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func TestPrintApplicationHistoryTable(t *testing.T) {
return nil
})

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

if output != expectation {
t.Fatalf("Incorrect print operation output %q, should be %q", output, expectation)
Expand Down Expand Up @@ -660,7 +660,7 @@ func TestPrintApplicationHistoryTableWithMultipleSources(t *testing.T) {
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"
expectation := "SOURCE 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)
Expand Down

0 comments on commit b6a0273

Please sign in to comment.