mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
Vendor dependencies
This commit is contained in:
committed by
Zlatko Čalušić
parent
2f0a16d8b7
commit
6054876201
60
vendor/goji.io/pat/match_test.go
generated
vendored
Normal file
60
vendor/goji.io/pat/match_test.go
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
package pat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"goji.io/pattern"
|
||||
)
|
||||
|
||||
func TestExistingContext(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
pat := New("/hi/:c/:a/:r/:l")
|
||||
req, err := http.NewRequest("GET", "/hi/foo/bar/baz/quux", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
ctx = pattern.SetPath(ctx, req.URL.EscapedPath())
|
||||
ctx = context.WithValue(ctx, pattern.AllVariables, map[pattern.Variable]interface{}{
|
||||
"hello": "world",
|
||||
"c": "nope",
|
||||
})
|
||||
ctx = context.WithValue(ctx, pattern.Variable("user"), "carl")
|
||||
|
||||
req = req.WithContext(ctx)
|
||||
req = pat.Match(req)
|
||||
if req == nil {
|
||||
t.Fatalf("expected pattern to match")
|
||||
}
|
||||
ctx = req.Context()
|
||||
|
||||
expected := map[pattern.Variable]interface{}{
|
||||
"c": "foo",
|
||||
"a": "bar",
|
||||
"r": "baz",
|
||||
"l": "quux",
|
||||
}
|
||||
for k, v := range expected {
|
||||
if p := Param(req, string(k)); p != v {
|
||||
t.Errorf("expected %s=%q, got %q", k, v, p)
|
||||
}
|
||||
}
|
||||
|
||||
expected["hello"] = "world"
|
||||
all := ctx.Value(pattern.AllVariables).(map[pattern.Variable]interface{})
|
||||
if !reflect.DeepEqual(all, expected) {
|
||||
t.Errorf("expected %v, got %v", expected, all)
|
||||
}
|
||||
|
||||
if path := pattern.Path(ctx); path != "" {
|
||||
t.Errorf("expected path=%q, got %q", "", path)
|
||||
}
|
||||
|
||||
if user := ctx.Value(pattern.Variable("user")); user != "carl" {
|
||||
t.Errorf("expected user=%q, got %q", "carl", user)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user