(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestRewriteURL(t *testing.T) { |
| 18 | var testCases = []struct { |
| 19 | whenURL string |
| 20 | expectPath string |
| 21 | expectRawPath string |
| 22 | expectQuery string |
| 23 | expectErr string |
| 24 | }{ |
| 25 | { |
| 26 | whenURL: "http://localhost:8080/old", |
| 27 | expectPath: "/new", |
| 28 | expectRawPath: "", |
| 29 | }, |
| 30 | { // encoded `ol%64` (decoded `old`) should not be rewritten to `/new` |
| 31 | whenURL: "/ol%64", // `%64` is decoded `d` |
| 32 | expectPath: "/old", |
| 33 | expectRawPath: "/ol%64", |
| 34 | }, |
| 35 | { |
| 36 | whenURL: "http://localhost:8080/users/+_+/orders/___++++?test=1", |
| 37 | expectPath: "/user/+_+/order/___++++", |
| 38 | expectRawPath: "", |
| 39 | expectQuery: "test=1", |
| 40 | }, |
| 41 | { |
| 42 | whenURL: "http://localhost:8080/users/%20a/orders/%20aa", |
| 43 | expectPath: "/user/ a/order/ aa", |
| 44 | expectRawPath: "", |
| 45 | }, |
| 46 | { |
| 47 | whenURL: "http://localhost:8080/%47%6f%2f?test=1", |
| 48 | expectPath: "/Go/", |
| 49 | expectRawPath: "/%47%6f%2f", |
| 50 | expectQuery: "test=1", |
| 51 | }, |
| 52 | { |
| 53 | whenURL: "/users/jill/orders/T%2FcO4lW%2Ft%2FVp%2F", |
| 54 | expectPath: "/user/jill/order/T/cO4lW/t/Vp/", |
| 55 | expectRawPath: "/user/jill/order/T%2FcO4lW%2Ft%2FVp%2F", |
| 56 | }, |
| 57 | { // do nothing, replace nothing |
| 58 | whenURL: "http://localhost:8080/user/jill/order/T%2FcO4lW%2Ft%2FVp%2F", |
| 59 | expectPath: "/user/jill/order/T/cO4lW/t/Vp/", |
| 60 | expectRawPath: "/user/jill/order/T%2FcO4lW%2Ft%2FVp%2F", |
| 61 | }, |
| 62 | { |
| 63 | whenURL: "http://localhost:8080/static", |
| 64 | expectPath: "/static/path", |
| 65 | expectRawPath: "", |
| 66 | expectQuery: "role=AUTHOR&limit=1000", |
| 67 | }, |
| 68 | { |
| 69 | whenURL: "/static", |
| 70 | expectPath: "/static/path", |
| 71 | expectRawPath: "", |
| 72 | expectQuery: "role=AUTHOR&limit=1000", |
| 73 | }, |
| 74 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…