(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestTarget_BuildRedirectURL(t *testing.T) { |
| 10 | type routeTest struct { |
| 11 | req string |
| 12 | want string |
| 13 | } |
| 14 | tests := []struct { |
| 15 | route string |
| 16 | tests []routeTest |
| 17 | }{ |
| 18 | { // simple absolute redirect |
| 19 | route: "route add svc / http://bar.com/", |
| 20 | tests: []routeTest{ |
| 21 | {req: "/", want: "http://bar.com/"}, |
| 22 | {req: "/abc", want: "http://bar.com/"}, |
| 23 | {req: "/a/b/c", want: "http://bar.com/"}, |
| 24 | {req: "/?aaa=1", want: "http://bar.com/"}, |
| 25 | }, |
| 26 | }, |
| 27 | { // absolute redirect to deep path with query |
| 28 | route: "route add svc / http://bar.com/a/b/c?foo=bar", |
| 29 | tests: []routeTest{ |
| 30 | {req: "/", want: "http://bar.com/a/b/c?foo=bar"}, |
| 31 | {req: "/abc", want: "http://bar.com/a/b/c?foo=bar"}, |
| 32 | {req: "/a/b/c", want: "http://bar.com/a/b/c?foo=bar"}, |
| 33 | {req: "/?aaa=1", want: "http://bar.com/a/b/c?foo=bar"}, |
| 34 | }, |
| 35 | }, |
| 36 | { // simple http -> https redirect with static path |
| 37 | route: "route add redirect *:80/ https://$host/", |
| 38 | tests: []routeTest{ |
| 39 | {req: "/", want: "https://foo.com/"}, |
| 40 | {req: "/abc", want: "https://foo.com/"}, |
| 41 | {req: "/a/b/c", want: "https://foo.com/"}, |
| 42 | {req: "/?aaa=1", want: "https://foo.com/"}, |
| 43 | {req: "/abc/?aaa=1", want: "https://foo.com/"}, |
| 44 | }, |
| 45 | }, |
| 46 | { // simple redirect to corresponding path |
| 47 | route: "route add svc / http://bar.com/$path", |
| 48 | tests: []routeTest{ |
| 49 | {req: "/", want: "http://bar.com/"}, |
| 50 | {req: "/abc", want: "http://bar.com/abc"}, |
| 51 | {req: "/a/b/c", want: "http://bar.com/a/b/c"}, |
| 52 | {req: "/?aaa=1", want: "http://bar.com/?aaa=1"}, |
| 53 | {req: "/abc/?aaa=1", want: "http://bar.com/abc/?aaa=1"}, |
| 54 | }, |
| 55 | }, |
| 56 | { // simple http -> https redirect to corresponding host & path |
| 57 | route: "route add redirect *:80/ https://$host/$path", |
| 58 | tests: []routeTest{ |
| 59 | {req: "/", want: "https://foo.com/"}, |
| 60 | {req: "/abc", want: "https://foo.com/abc"}, |
| 61 | {req: "/a/b/c", want: "https://foo.com/a/b/c"}, |
| 62 | {req: "/?aaa=1", want: "https://foo.com/?aaa=1"}, |
| 63 | {req: "/abc/?aaa=1", want: "https://foo.com/abc/?aaa=1"}, |
| 64 | }, |
| 65 | }, |
| 66 | { // simple redirect to corresponding path without / before $path |
nothing calls this directly
no test coverage detected