Skip to content

Commit

Permalink
Fix loop var
Browse files Browse the repository at this point in the history
  • Loading branch information
kramvan1 committed Jan 21, 2025
1 parent 1ef2239 commit 6a368b0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 1 addition & 2 deletions rules/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ func formatPath(pattern string, m Attributes) (string, bool) {
if strings.HasPrefix(path, ":") {
attr := m.GetAttribute(path[1:])
if attr == nil {
s := path
attr = &s
attr = &path
allFound = false
}
result.WriteString(*attr)
Expand Down
40 changes: 40 additions & 0 deletions rules/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,43 @@ func TestNoRegex(t *testing.T) {
t.Fail()
}
}

func TestFormatPath(t *testing.T) {
testCases := []struct {
name string
pattern string
atttributes Attributes
result string
allFound bool
}{
{
"Happy path",
"/:region/test",
NewAttributes(map[string]string{"region": "region"}),
"/region/test",
true,
},
{
"Empty path",
"",
NewAttributes(map[string]string{"region": "region"}),
"",
true,
},
{
"Missing attribute",
"/:region/test",
NewAttributes(map[string]string{}),
"/:region/test",
false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result, allFound := formatPath(tc.pattern, tc.atttributes)
assert.Equal(t, tc.result, result)
assert.Equal(t, tc.allFound, allFound)
})
}
}

0 comments on commit 6a368b0

Please sign in to comment.