| 54 | } |
| 55 | |
| 56 | func TestCallerListWithQueryParams(t *testing.T) { |
| 57 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 58 | if r.URL.Query().Get("actorId") != "u-7" { |
| 59 | t.Errorf("actorId = %q", r.URL.Query().Get("actorId")) |
| 60 | } |
| 61 | if r.URL.Query().Get("limit") != "50" { |
| 62 | t.Errorf("limit = %q", r.URL.Query().Get("limit")) |
| 63 | } |
| 64 | w.Header().Set("Content-Type", "application/json") |
| 65 | _, _ = w.Write([]byte(`{"data":[{"id":1},{"id":2}]}`)) |
| 66 | })) |
| 67 | defer srv.Close() |
| 68 | |
| 69 | op := &OpDescriptor{ |
| 70 | OperationID: "listAuditLogs", |
| 71 | Method: "GET", |
| 72 | PathTemplate: "/audit-logs", |
| 73 | QueryParams: []ParamSpec{ |
| 74 | {Name: "actorId", In: ParamInQuery}, |
| 75 | {Name: "limit", In: ParamInQuery}, |
| 76 | }, |
| 77 | ResultPath: []string{"data"}, |
| 78 | IsArrayResponse: true, |
| 79 | } |
| 80 | c := buildCaller(t, op, srv.URL, nil) |
| 81 | |
| 82 | body, err := c.Call(context.Background(), CallParams{ |
| 83 | QueryValues: map[string]string{"actorId": "u-7", "limit": "50"}, |
| 84 | }) |
| 85 | if err != nil { |
| 86 | t.Fatal(err) |
| 87 | } |
| 88 | // ResultPath strips the {data: [...]} wrapper. |
| 89 | if string(body) != `[{"id":1},{"id":2}]` { |
| 90 | t.Errorf("body = %s", body) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | func TestCallerRetryOn401(t *testing.T) { |
| 95 | var calls int32 |