Skip to content

Commit

Permalink
Move TestNativeContextMiddleware to mux_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
fharding1 committed Oct 24, 2019
1 parent faac3f3 commit 04da6ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
30 changes: 0 additions & 30 deletions context_test.go

This file was deleted.

24 changes: 24 additions & 0 deletions mux_test.go
Expand Up @@ -7,6 +7,7 @@ package mux
import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -16,6 +17,7 @@ import (
"reflect"
"strings"
"testing"
"time"
)

func (r *Route) GoString() string {
Expand Down Expand Up @@ -2804,6 +2806,28 @@ func TestSubrouterNotFound(t *testing.T) {
}
}

func TestContextMiddleware(t *testing.T) {
withTimeout := func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), time.Minute)
defer cancel()
h.ServeHTTP(w, r.WithContext(ctx))
})
}

r := NewRouter()
r.Handle("/path/{foo}", withTimeout(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := Vars(r)
if vars["foo"] != "bar" {
t.Fatal("Expected foo var to be set")
}
})))

rec := NewRecorder()
req := newRequest("GET", "/path/bar")
r.ServeHTTP(rec, req)
}

// mapToPairs converts a string map to a slice of string pairs
func mapToPairs(m map[string]string) []string {
var i int
Expand Down

0 comments on commit 04da6ef

Please sign in to comment.