@@ -2,49 +2,28 @@ package argocd
2
2
3
3
import (
4
4
"testing"
5
- gitm "github.com/argoproj-labs/argocd-image-updater/ext/git/mocks"
6
5
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
7
6
v1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
8
7
)
9
8
10
- // Test that batched writer does not mix different branches in one commit/push
11
- func TestRepoWriter_GroupsByBranch (t * testing.T ) {
12
- // Build two apps targeting different write branches via annotation
13
- appA := & v1alpha1.Application {}
14
- appA .Annotations = map [string ]string {
15
- common .WriteBackMethodAnnotation : "git" ,
16
- common .GitBranchAnnotation : "main:appA-branch" ,
17
- }
18
- appB := & v1alpha1.Application {}
19
- appB .Annotations = map [string ]string {
20
- common .WriteBackMethodAnnotation : "git" ,
21
- common .GitBranchAnnotation : "main:appB-branch" ,
22
- }
23
-
24
- // Minimal wbc for both
25
- wbcA := & WriteBackConfig {GitRepo : "https://example/repo.git" , GitCommitUser : "u" , GitCommitEmail : "e" }
26
- wbcB := & WriteBackConfig {GitRepo : "https://example/repo.git" , GitCommitUser : "u" , GitCommitEmail : "e" }
27
- // bind write-branch via parseGitConfig path expectation (we rely on getWriteBackBranch during grouping)
28
- wbcA .GitWriteBranch = "appA-branch"
29
- wbcB .GitWriteBranch = "appB-branch"
30
-
31
- // Use mocks for git client by intercepting commitChangesGit is hard; instead, exercise grouping directly.
32
- rw := & repoWriter {repoURL : wbcA .GitRepo }
33
- // Replace commitBatch with an interceptor
34
- got := make (map [string ]int )
35
- rw .commitBatch = func (branch string , intents []writeIntent ) { got [branch ] = len (intents ) }
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" }
36
15
37
- rw . flushBatch ([]writeIntent {
16
+ by := groupIntentsByBranch ([]writeIntent {
38
17
{app : appA , wbc : wbcA , changeList : []ChangeEntry {{}}, writeFn : writeOverrides },
39
18
{app : appB , wbc : wbcB , changeList : []ChangeEntry {{}}, writeFn : writeOverrides },
40
19
{app : appA , wbc : wbcA , changeList : []ChangeEntry {{}}, writeFn : writeOverrides },
41
20
})
42
21
43
- if got ["appA-branch" ] != 2 {
44
- t .Fatalf ("expected 2 intents for appA-branch, got %d" , got ["appA-branch" ])
22
+ if len ( by ["appA-branch" ]) != 2 {
23
+ t .Fatalf ("expected 2 intents for appA-branch, got %d" , len ( by ["appA-branch" ]) )
45
24
}
46
- if got ["appB-branch" ] != 1 {
47
- t .Fatalf ("expected 1 intent for appB-branch, got %d" , got ["appB-branch" ])
25
+ if len ( by ["appB-branch" ]) != 1 {
26
+ t .Fatalf ("expected 1 intent for appB-branch, got %d" , len ( by ["appB-branch" ]) )
48
27
}
49
28
}
50
29
0 commit comments