| 1 | package pattern |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | type boolPattern bool |
| 10 | |
| 11 | func (b boolPattern) Match(ctx context.Context, r *http.Request) context.Context { |
| 12 | if b { |
| 13 | return ctx |
| 14 | } |
| 15 | return nil |
| 16 | } |
| 17 | |
| 18 | type prefixPattern string |
| 19 | |
| 20 | func (p prefixPattern) Match(ctx context.Context, r *http.Request) context.Context { |
| 21 | return ctx |
| 22 | } |
| 23 | func (p prefixPattern) PathPrefix() string { |
| 24 | return string(p) |
| 25 | } |
| 26 | |
| 27 | func TestPathRoundTrip(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | ctx := SetPath(context.Background(), "hi") |
| 31 | if path := Path(ctx); path != "hi" { |
| 32 | t.Errorf("expected hi, got %q", path) |
| 33 | } |
| 34 | |
| 35 | if path := Path(context.Background()); path != "" { |
| 36 | t.Errorf("expected empty path, got %q", path) |
| 37 | } |
| 38 | } |