Skip to content

Commit a562645

Browse files
committed
test: cover splitTrimmed per-element CORS whitespace handling
1 parent 4b7238f commit a562645

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

plugin_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,51 @@ func TestMiddleware_NoSpanWithoutOtelContext(t *testing.T) {
9090
assert.Nil(t, headersSpan, "no span should be created without OtelTracerNameKey")
9191
}
9292

93+
func TestSplitTrimmed(t *testing.T) {
94+
tests := []struct {
95+
name string
96+
in string
97+
want []string
98+
}{
99+
{
100+
name: "single value",
101+
in: "GET",
102+
want: []string{"GET"},
103+
},
104+
{
105+
name: "methods with space after comma",
106+
in: "GET, POST",
107+
want: []string{"GET", "POST"},
108+
},
109+
{
110+
name: "headers with spaces around commas",
111+
in: "Cache-Control, Content-Type",
112+
want: []string{"Cache-Control", "Content-Type"},
113+
},
114+
{
115+
name: "no spaces preserves values",
116+
in: "GET,POST,PUT,DELETE",
117+
want: []string{"GET", "POST", "PUT", "DELETE"},
118+
},
119+
{
120+
name: "leading and trailing whitespace per element",
121+
in: " GET ,\tPOST\t, PUT ",
122+
want: []string{"GET", "POST", "PUT"},
123+
},
124+
{
125+
name: "wildcard",
126+
in: "*",
127+
want: []string{"*"},
128+
},
129+
}
130+
131+
for _, tt := range tests {
132+
t.Run(tt.name, func(t *testing.T) {
133+
assert.Equal(t, tt.want, splitTrimmed(tt.in))
134+
})
135+
}
136+
}
137+
93138
func newTestPlugin() *Plugin {
94139
return &Plugin{
95140
cfg: &Config{

0 commit comments

Comments
 (0)