| 21 | } |
| 22 | |
| 23 | func TestCallerRowJoinPath(t *testing.T) { |
| 24 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 25 | // RequestURI carries the escaped wire form; r.URL.Path is the |
| 26 | // decoded version. Asserting on RequestURI ensures the client |
| 27 | // actually escaped the space rather than relying on the server |
| 28 | // to be lenient. |
| 29 | if r.RequestURI != "/users/abc%20123" { |
| 30 | t.Errorf("RequestURI = %q, want /users/abc%%20123", r.RequestURI) |
| 31 | } |
| 32 | w.Header().Set("Content-Type", "application/json") |
| 33 | _, _ = w.Write([]byte(`{"id":"abc 123","email":"u@x"}`)) |
| 34 | })) |
| 35 | defer srv.Close() |
| 36 | |
| 37 | op := &OpDescriptor{ |
| 38 | OperationID: "getUserById", |
| 39 | Method: "GET", |
| 40 | PathTemplate: "/users/{userId}", |
| 41 | PathParams: []ParamSpec{{Name: "userId", In: ParamInPath, Required: true, Type: "string"}}, |
| 42 | } |
| 43 | c := buildCaller(t, op, srv.URL, nil) |
| 44 | |
| 45 | body, err := c.Call(context.Background(), CallParams{ |
| 46 | PathValues: map[string]string{"userId": "abc 123"}, |
| 47 | }) |
| 48 | if err != nil { |
| 49 | t.Fatalf("Call: %v", err) |
| 50 | } |
| 51 | if !contains(string(body), `"abc 123"`) { |
| 52 | t.Errorf("body = %s", body) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | func TestCallerListWithQueryParams(t *testing.T) { |
| 57 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |