update packaging
[platform/core/system/edge-orchestration.git] / vendor / github.com / gorilla / mux / context_test.go
1 package mux
2
3 import (
4         "context"
5         "net/http"
6         "testing"
7         "time"
8 )
9
10 func TestNativeContextMiddleware(t *testing.T) {
11         withTimeout := func(h http.Handler) http.Handler {
12                 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13                         ctx, cancel := context.WithTimeout(r.Context(), time.Minute)
14                         defer cancel()
15                         h.ServeHTTP(w, r.WithContext(ctx))
16                 })
17         }
18
19         r := NewRouter()
20         r.Handle("/path/{foo}", withTimeout(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
21                 vars := Vars(r)
22                 if vars["foo"] != "bar" {
23                         t.Fatal("Expected foo var to be set")
24                 }
25         })))
26
27         rec := NewRecorder()
28         req := newRequest("GET", "/path/bar")
29         r.ServeHTTP(rec, req)
30 }