Skip to content

Commit 6a368b0

Browse files
committed
Fix loop var
1 parent 1ef2239 commit 6a368b0

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

rules/matcher.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ func formatPath(pattern string, m Attributes) (string, bool) {
134134
if strings.HasPrefix(path, ":") {
135135
attr := m.GetAttribute(path[1:])
136136
if attr == nil {
137-
s := path
138-
attr = &s
137+
attr = &path
139138
allFound = false
140139
}
141140
result.WriteString(*attr)

rules/matcher_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,43 @@ func TestNoRegex(t *testing.T) {
7272
t.Fail()
7373
}
7474
}
75+
76+
func TestFormatPath(t *testing.T) {
77+
testCases := []struct {
78+
name string
79+
pattern string
80+
atttributes Attributes
81+
result string
82+
allFound bool
83+
}{
84+
{
85+
"Happy path",
86+
"/:region/test",
87+
NewAttributes(map[string]string{"region": "region"}),
88+
"/region/test",
89+
true,
90+
},
91+
{
92+
"Empty path",
93+
"",
94+
NewAttributes(map[string]string{"region": "region"}),
95+
"",
96+
true,
97+
},
98+
{
99+
"Missing attribute",
100+
"/:region/test",
101+
NewAttributes(map[string]string{}),
102+
"/:region/test",
103+
false,
104+
},
105+
}
106+
107+
for _, tc := range testCases {
108+
t.Run(tc.name, func(t *testing.T) {
109+
result, allFound := formatPath(tc.pattern, tc.atttributes)
110+
assert.Equal(t, tc.result, result)
111+
assert.Equal(t, tc.allFound, allFound)
112+
})
113+
}
114+
}

0 commit comments

Comments
 (0)