26 lines
804 B
Go
26 lines
804 B
Go
package main
|
|||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestEtagMatchesUsesWeakComparison(t *testing.T) {
|
||
|
|
const etag = `W/"abc"`
|
||
|
|
cases := []struct {
|
||
|
|
name string
|
||
|
|
ifNoneMatch string
|
||
|
|
want bool
|
||
|
|
}{
|
||
|
|
{name: "missing header", ifNoneMatch: "", want: false},
|
||
|
|
{name: "same weak tag", ifNoneMatch: `W/"abc"`, want: true},
|
||
|
|
{name: "strong form of same tag", ifNoneMatch: `"abc"`, want: true},
|
||
|
|
{name: "one of several tags", ifNoneMatch: `"x", W/"abc"`, want: true},
|
||
|
|
{name: "different tag", ifNoneMatch: `W/"def"`, want: false},
|
||
|
|
{name: "wildcard", ifNoneMatch: "*", want: true},
|
||
|
|
}
|
||
|
|
for _, tc := range cases {
|
||
|
|
t.Run(tc.name, func(t *testing.T) {
|
||
|
|
if got := etagMatches(tc.ifNoneMatch, etag); got != tc.want {
|
||
|
|
t.Fatalf("etagMatches(%q) = %v, want %v", tc.ifNoneMatch, got, tc.want)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|