Tests validate the query encoder.
(t *testing.T)
| 309 | |
| 310 | // Tests validate the query encoder. |
| 311 | func TestQueryEncode(t *testing.T) { |
| 312 | testCases := []struct { |
| 313 | queryKey string |
| 314 | valueToEncode []string |
| 315 | // Expected result. |
| 316 | result string |
| 317 | }{ |
| 318 | {"prefix", []string{"test@123", "test@456"}, "prefix=test%40123&prefix=test%40456"}, |
| 319 | {"@prefix", []string{"test@123"}, "%40prefix=test%40123"}, |
| 320 | {"@prefix", []string{"a/b/c/"}, "%40prefix=a%2Fb%2Fc%2F"}, |
| 321 | {"prefix", []string{"test#123"}, "prefix=test%23123"}, |
| 322 | {"prefix#", []string{"test#123"}, "prefix%23=test%23123"}, |
| 323 | {"prefix", []string{"test123"}, "prefix=test123"}, |
| 324 | {"prefix", []string{"test本語123", "test123"}, "prefix=test%E6%9C%AC%E8%AA%9E123&prefix=test123"}, |
| 325 | } |
| 326 | |
| 327 | for i, testCase := range testCases { |
| 328 | urlValues := make(url.Values) |
| 329 | for _, valueToEncode := range testCase.valueToEncode { |
| 330 | urlValues.Add(testCase.queryKey, valueToEncode) |
| 331 | } |
| 332 | result := QueryEncode(urlValues) |
| 333 | if testCase.result != result { |
| 334 | t.Errorf("Test %d: Expected queryEncode result to be \"%s\", but found it to be \"%s\" instead", i+1, testCase.result, result) |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // Tests validate the URL path encoder. |
| 340 | func TestEncodePath(t *testing.T) { |
nothing calls this directly
no test coverage detected