Skip to content

Commit 94231ff

Browse files
brandon-heightkisielk
authored andcommitted
Fix table-driven example documentation (#363)
Prior to this change, the example documentation found in the README.md has an errant code which won't work in the table-driven code example. This change modifies the variable name from `t` to `tc` so it does not conflict with the `t *testing.T` struct definition. * Adds a range clause to the `for` statement * Modifies `for` statement scope to use `tc.shouldPass`, and `tc.routeVariable` Doc: https://github.com/gorilla/mux#testing-handlers
1 parent 4dbd923 commit 94231ff

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ func TestMetricsHandler(t *testing.T) {
593593
{"adhadaeqm3k", false},
594594
}
595595

596-
for _, t := tt {
597-
path := fmt.Sprintf("/metrics/%s", t.routeVariable)
596+
for _, tc := range tt {
597+
path := fmt.Sprintf("/metrics/%s", tc.routeVariable)
598598
req, err := http.NewRequest("GET", path, nil)
599599
if err != nil {
600600
t.Fatal(err)
@@ -606,9 +606,9 @@ func TestMetricsHandler(t *testing.T) {
606606

607607
// In this case, our MetricsHandler returns a non-200 response
608608
// for a route variable it doesn't know about.
609-
if rr.Code == http.StatusOK && !t.shouldPass {
609+
if rr.Code == http.StatusOK && !tc.shouldPass {
610610
t.Errorf("handler should have failed on routeVariable %s: got %v want %v",
611-
t.routeVariable, rr.Code, http.StatusOK)
611+
tc.routeVariable, rr.Code, http.StatusOK)
612612
}
613613
}
614614
}

0 commit comments

Comments
 (0)