Skip to content

Commit 4f6b8a6

Browse files
author
Eidmantas Ivanauskas
committed
test(git): move branch grouping test to separate file
1 parent 48e2692 commit 4f6b8a6

File tree

2 files changed

+28
-463
lines changed

2 files changed

+28
-463
lines changed

pkg/argocd/git_grouping_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package argocd
2+
3+
import (
4+
"testing"
5+
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
6+
v1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
7+
)
8+
9+
// Test that grouping does not mix different branches in one commit/push
10+
func Test_groupIntentsByBranch(t *testing.T) {
11+
appA := &v1alpha1.Application{Annotations: map[string]string{common.GitBranchAnnotation: "main:appA-branch"}}
12+
appB := &v1alpha1.Application{Annotations: map[string]string{common.GitBranchAnnotation: "main:appB-branch"}}
13+
wbcA := &WriteBackConfig{GitRepo: "https://example/repo.git", GitWriteBranch: "appA-branch"}
14+
wbcB := &WriteBackConfig{GitRepo: "https://example/repo.git", GitWriteBranch: "appB-branch"}
15+
16+
by := groupIntentsByBranch([]writeIntent{
17+
{app: appA, wbc: wbcA, changeList: []ChangeEntry{{}}, writeFn: writeOverrides},
18+
{app: appB, wbc: wbcB, changeList: []ChangeEntry{{}}, writeFn: writeOverrides},
19+
{app: appA, wbc: wbcA, changeList: []ChangeEntry{{}}, writeFn: writeOverrides},
20+
})
21+
22+
if len(by["appA-branch"]) != 2 {
23+
t.Fatalf("expected 2 intents for appA-branch, got %d", len(by["appA-branch"]))
24+
}
25+
if len(by["appB-branch"]) != 1 {
26+
t.Fatalf("expected 1 intent for appB-branch, got %d", len(by["appB-branch"]))
27+
}
28+
}

0 commit comments

Comments
 (0)