Skip to content

Commit

Permalink
try next level after upper level is included (#1897)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored Apr 25, 2022
1 parent 4cec52a commit d685914
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,11 @@ func matchKey(rules []rule, key string) bool {
logger.Fatalf("match %s with %s: %v", rule.pattern, suffix, err)
}
if ok {
return rule.include
if rule.include {
break // try next level
} else {
return false
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ func TestSuffixForPath(t *testing.T) {
}
for _, tt := range tests {
if got := suffixForPattern(tt.key, tt.pattern); !reflect.DeepEqual(got, tt.want) {
t.Errorf("slidingWindowForPath() = %v, want %v", got, tt.want)
t.Errorf("suffixForPattern() = %v, want %v", got, tt.want)
}
}
}
Expand Down Expand Up @@ -562,10 +562,11 @@ func TestMatchObjects(t *testing.T) {
{rules: []rule{{pattern: "a.go", include: true}, {pattern: "pkg", include: false}}, key: "a/pkg/c/a.go", want: false},
{rules: []rule{{pattern: "a", include: false}, {pattern: "pkg", include: true}}, key: "a/pkg/c/a.go", want: false},
{rules: []rule{{pattern: "a.go", include: true}, {pattern: "pkg", include: false}}, key: "", want: true},
{rules: []rule{{pattern: "a", include: true}, {pattern: "b/", include: false}, {pattern: "c", include: true}}, key: "a/b/c", want: false},
}
for _, tt := range tests {
if got := matchKey(tt.rules, tt.key); got != tt.want {
t.Errorf("includeObject() = %v, want %v", got, tt.want)
t.Errorf("matchKey() = %v, want %v", got, tt.want)
}
}
}

0 comments on commit d685914

Please sign in to comment.