Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2546,13 +2546,13 @@ func TestMethodsSubrouterPathVariable(t *testing.T) {
}
}

func ExampleSetURLVars() {
func TestExampleSetURLVars(t *testing.T) {
req, _ := http.NewRequest("GET", "/foo", nil)
req = SetURLVars(req, map[string]string{"foo": "bar"})
req = SetURLVars(t, req, map[string]string{"foo": "bar"})

fmt.Println(Vars(req)["foo"])

// Output: bar
if val := Vars(req)["foo"]; val != "bar" {
t.Errorf("Expected URL var 'foo' to be 'bar', but got %q", val)
}
}

// testMethodsSubrouter runs an individual methodsSubrouterTest.
Expand Down
8 changes: 6 additions & 2 deletions test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package mux

import "net/http"
import (
"net/http"
"testing"
)

// SetURLVars sets the URL variables for the given request, to be accessed via
// mux.Vars for testing route behaviour. Arguments are not modified, a shallow
Expand All @@ -14,6 +17,7 @@ import "net/http"
// inject variables into the request context. Alternatively, URL variables
// can be set by making a route that captures the required variables,
// starting a server and sending the request to that server.
func SetURLVars(r *http.Request, val map[string]string) *http.Request {
func SetURLVars(t *testing.T, r *http.Request, val map[string]string) *http.Request {
t.Helper()
return requestWithVars(r, val)
}
Loading