(t *testing.T)
| 429 | } |
| 430 | |
| 431 | func TestQueryOpsRenameNoOpCases(t *testing.T) { |
| 432 | repl := caddy.NewReplacer() |
| 433 | |
| 434 | for i, tc := range []struct { |
| 435 | input *http.Request |
| 436 | expect map[string][]string |
| 437 | ops *queryOps |
| 438 | }{ |
| 439 | { |
| 440 | ops: &queryOps{ |
| 441 | Rename: []queryOpsArguments{{Key: "ID", Val: "id"}}, |
| 442 | }, |
| 443 | input: newRequest(t, "GET", "/?page=test&id=5&test=100"), |
| 444 | expect: map[string][]string{"id": {"5"}, "page": {"test"}, "test": {"100"}}, |
| 445 | }, |
| 446 | { |
| 447 | ops: &queryOps{ |
| 448 | Rename: []queryOpsArguments{{Key: "id", Val: "id"}}, |
| 449 | }, |
| 450 | input: newRequest(t, "GET", "/?page=test&id=5&test=100"), |
| 451 | expect: map[string][]string{"id": {"5"}, "page": {"test"}, "test": {"100"}}, |
| 452 | }, |
| 453 | { |
| 454 | ops: &queryOps{ |
| 455 | Rename: []queryOpsArguments{{Key: "ID", Val: "id"}}, |
| 456 | }, |
| 457 | input: newRequest(t, "GET", "/?page=test&ID=5&test=100"), |
| 458 | expect: map[string][]string{"id": {"5"}, "page": {"test"}, "test": {"100"}}, |
| 459 | }, |
| 460 | { |
| 461 | ops: &queryOps{ |
| 462 | Rename: []queryOpsArguments{{Key: "ID", Val: "id"}}, |
| 463 | }, |
| 464 | input: newRequest(t, "GET", "/?page=test&ID=5&id=7&test=100"), |
| 465 | expect: map[string][]string{"id": {"5"}, "page": {"test"}, "test": {"100"}}, |
| 466 | }, |
| 467 | } { |
| 468 | repl.Set("http.request.uri", tc.input.RequestURI) |
| 469 | repl.Set("http.request.uri.path", tc.input.URL.Path) |
| 470 | repl.Set("http.request.uri.query", tc.input.URL.RawQuery) |
| 471 | |
| 472 | tc.ops.do(tc.input, repl) |
| 473 | |
| 474 | if actual := tc.input.URL.Query(); !reflect.DeepEqual(tc.expect, map[string][]string(actual)) { |
| 475 | t.Errorf("Test %d: Expected query=%v but got %v", i, tc.expect, actual) |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | func newRequest(t *testing.T, method, uri string) *http.Request { |
| 481 | req, err := http.NewRequest(method, uri, nil) |
nothing calls this directly
no test coverage detected