|
5 | 5 | package bitbucketv1 |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "io" |
| 9 | + "net/http" |
| 10 | + "net/http/httptest" |
8 | 11 | "os" |
9 | 12 | "reflect" |
10 | 13 | "testing" |
@@ -2331,6 +2334,89 @@ func TestDefaultApiService_GetBranches(t *testing.T) { |
2331 | 2334 | } |
2332 | 2335 | } |
2333 | 2336 |
|
| 2337 | +func TestDefaultApiService_GetBranchesPagination(t *testing.T) { |
| 2338 | + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 2339 | + w.Header().Set("Content-Type", "application/json") |
| 2340 | + switch r.RequestURI { |
| 2341 | + case "/api/1.0/projects/PROJECT/repos/REPO/branches?limit=100&start=0": |
| 2342 | + _, err := io.WriteString(w, `{ |
| 2343 | + "size": 1, |
| 2344 | + "limit": 100, |
| 2345 | + "isLastPage": true, |
| 2346 | + "values": [ |
| 2347 | + { |
| 2348 | + "id": "refs/heads/main", |
| 2349 | + "displayId": "main", |
| 2350 | + "type": "BRANCH", |
| 2351 | + "latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13", |
| 2352 | + "latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13", |
| 2353 | + "isDefault": true |
| 2354 | + } |
| 2355 | + ], |
| 2356 | + "start": 0 |
| 2357 | + }`) |
| 2358 | + if err != nil { |
| 2359 | + t.Errorf("DefaultApiService.GetBranches() error = i/o error %v", err) |
| 2360 | + } |
| 2361 | + default: |
| 2362 | + t.Errorf("DefaultApiService.GetBranches() error = unhandled request %s", r.RequestURI) |
| 2363 | + } |
| 2364 | + })) |
| 2365 | + defer ts.Close() |
| 2366 | + |
| 2367 | + client := NewAPIClient( |
| 2368 | + context.TODO(), |
| 2369 | + NewConfiguration(ts.URL), |
| 2370 | + ) |
| 2371 | + type fields struct { |
| 2372 | + client *APIClient |
| 2373 | + } |
| 2374 | + type args struct { |
| 2375 | + project string |
| 2376 | + repository string |
| 2377 | + localVarOptionals map[string]interface{} |
| 2378 | + } |
| 2379 | + tests := []struct { |
| 2380 | + name string |
| 2381 | + fields fields |
| 2382 | + args args |
| 2383 | + want *APIResponse |
| 2384 | + wantErr, integrationTest bool |
| 2385 | + }{ |
| 2386 | + {"limitAndStartSet", fields{client: client}, args{ |
| 2387 | + project: "PROJECT", repository: "REPO", |
| 2388 | + localVarOptionals: map[string]interface{}{ |
| 2389 | + "limit": 100, |
| 2390 | + "start": 0, |
| 2391 | + }}, nil, false, false}, |
| 2392 | + {"incorrectLimit", fields{client: client}, args{ |
| 2393 | + project: "PROJECT", repository: "REPO", |
| 2394 | + localVarOptionals: map[string]interface{}{ |
| 2395 | + "limit": "wrong", |
| 2396 | + }}, nil, true, false}, |
| 2397 | + {"incorrectStart", fields{client: client}, args{ |
| 2398 | + project: "PROJECT", repository: "REPO", |
| 2399 | + localVarOptionals: map[string]interface{}{ |
| 2400 | + "start": "wrong", |
| 2401 | + }}, nil, true, false}, |
| 2402 | + } |
| 2403 | + for _, tt := range tests { |
| 2404 | + if tt.integrationTest != runIntegrationTests { |
| 2405 | + continue |
| 2406 | + } |
| 2407 | + t.Run(tt.name, func(t *testing.T) { |
| 2408 | + a := &DefaultApiService{ |
| 2409 | + client: tt.fields.client, |
| 2410 | + } |
| 2411 | + _, err := a.GetBranches(tt.args.project, tt.args.repository, tt.args.localVarOptionals) |
| 2412 | + if (err != nil) != tt.wantErr { |
| 2413 | + t.Errorf("DefaultApiService.GetBranches() error = %v, wantErr %v", err, tt.wantErr) |
| 2414 | + return |
| 2415 | + } |
| 2416 | + }) |
| 2417 | + } |
| 2418 | +} |
| 2419 | + |
2334 | 2420 | func TestDefaultApiService_GetChanges(t *testing.T) { |
2335 | 2421 | type fields struct { |
2336 | 2422 | client *APIClient |
|
0 commit comments