From 0fdf828bb28a79b519024e2e29915e851b73e580 Mon Sep 17 00:00:00 2001 From: Franklin Harding <32021905+fharding1@users.noreply.github.com> Date: Fri, 19 Jan 2018 22:28:49 -0800 Subject: [PATCH] [docs] Clarify SetURLVars (#335) * [docs] Clarify SetURLVars Clarify in documentation that SetURLVars does not modify the given *htttp.Request, provide an example of usage. * Short and sweet function doc, example test. --- mux_test.go | 9 +++++++++ test_helpers.go | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mux_test.go b/mux_test.go index 9e93c98..4591344 100644 --- a/mux_test.go +++ b/mux_test.go @@ -2248,6 +2248,15 @@ func TestMethodsSubrouterPathVariable(t *testing.T) { } } +func ExampleSetURLVars() { + req, _ := http.NewRequest("GET", "/foo", nil) + req = SetURLVars(req, map[string]string{"foo": "bar"}) + + fmt.Println(Vars(req)["foo"]) + + // Output: bar +} + // testMethodsSubrouter runs an individual methodsSubrouterTest. func testMethodsSubrouter(t *testing.T, test methodsSubrouterTest) { // Execute request diff --git a/test_helpers.go b/test_helpers.go index 8b2c4a4..32ecffd 100644 --- a/test_helpers.go +++ b/test_helpers.go @@ -7,7 +7,8 @@ package mux import "net/http" // SetURLVars sets the URL variables for the given request, to be accessed via -// mux.Vars for testing route behaviour. +// mux.Vars for testing route behaviour. Arguments are not modified, a shallow +// copy is returned. // // This API should only be used for testing purposes; it provides a way to // inject variables into the request context. Alternatively, URL variables