@@ -2388,6 +2388,133 @@ func TestDefaultApiService_GetBranches(t *testing.T) {
2388
2388
}
2389
2389
}
2390
2390
2391
+ func TestDefaultApiService_GetBranchesWithBoostMatches (t * testing.T ) {
2392
+ getBranch := func (res * APIResponse ) (branch string ) {
2393
+ if res .Values == nil {
2394
+ return ""
2395
+ }
2396
+ values , ok := res .Values ["values" ]
2397
+ if ! ok {
2398
+ return ""
2399
+ }
2400
+ valuesArray , ok := values .([]interface {})
2401
+ if ! ok || len (valuesArray ) == 0 {
2402
+ return ""
2403
+ }
2404
+ value , ok := valuesArray [0 ].(map [string ]interface {})
2405
+ if ! ok {
2406
+ return ""
2407
+ }
2408
+
2409
+ return value ["displayId" ].(string )
2410
+ }
2411
+
2412
+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2413
+ w .Header ().Set ("Content-Type" , "application/json" )
2414
+ switch r .RequestURI {
2415
+ case "/api/1.0/projects/PROJECT/repos/REPO/branches?boostMatches=true&filterText=foo&orderBy=ALPHABETICAL" :
2416
+ _ , err := io .WriteString (w , `{
2417
+ "size": 1,
2418
+ "limit": 100,
2419
+ "isLastPage": true,
2420
+ "values": [
2421
+ {
2422
+ "id": "refs/heads/foo",
2423
+ "displayId": "foo",
2424
+ "type": "BRANCH",
2425
+ "latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13",
2426
+ "latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13",
2427
+ "isDefault": true
2428
+ }
2429
+ ],
2430
+ "start": 0
2431
+ }` )
2432
+ if err != nil {
2433
+ t .Errorf ("DefaultApiService.GetBranches() error = i/o error %v" , err )
2434
+ }
2435
+ case "/api/1.0/projects/PROJECT/repos/REPO/branches?filterText=foo&orderBy=ALPHABETICAL" :
2436
+ _ , err := io .WriteString (w , `{
2437
+ "size": 1,
2438
+ "limit": 100,
2439
+ "isLastPage": true,
2440
+ "values": [
2441
+ {
2442
+ "id": "refs/heads/_foo_bar",
2443
+ "displayId": "_foo_bar",
2444
+ "type": "BRANCH",
2445
+ "latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13",
2446
+ "latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13",
2447
+ "isDefault": true
2448
+ }
2449
+ ],
2450
+ "start": 0
2451
+ }` )
2452
+ if err != nil {
2453
+ t .Errorf ("DefaultApiService.GetBranches() error = i/o error %v" , err )
2454
+ }
2455
+ default :
2456
+ t .Errorf ("DefaultApiService.GetBranches() error = unhandled request %s" , r .RequestURI )
2457
+ }
2458
+ }))
2459
+ defer ts .Close ()
2460
+
2461
+ client := NewAPIClient (
2462
+ context .TODO (),
2463
+ NewConfiguration (ts .URL ),
2464
+ )
2465
+ type fields struct {
2466
+ client * APIClient
2467
+ }
2468
+ type args struct {
2469
+ project string
2470
+ repository string
2471
+ localVarOptionals map [string ]interface {}
2472
+ }
2473
+ tests := []struct {
2474
+ name string
2475
+ fields fields
2476
+ args args
2477
+ wantBranch string
2478
+ wantErr , integrationTest bool
2479
+ }{
2480
+ {"withBoostMatches" , fields {client : client }, args {
2481
+ project : "PROJECT" , repository : "REPO" ,
2482
+ localVarOptionals : map [string ]interface {}{
2483
+ "boostMatches" : true ,
2484
+ "filterText" : "foo" ,
2485
+ "orderBy" : "ALPHABETICAL" ,
2486
+ }}, "foo" , false , false },
2487
+ {"withoutBoostMatches" , fields {client : client }, args {
2488
+ project : "PROJECT" , repository : "REPO" ,
2489
+ localVarOptionals : map [string ]interface {}{
2490
+ "filterText" : "foo" ,
2491
+ "orderBy" : "ALPHABETICAL" ,
2492
+ }}, "_foo_bar" , false , false },
2493
+ }
2494
+ for _ , tt := range tests {
2495
+ if tt .integrationTest != runIntegrationTests {
2496
+ continue
2497
+ }
2498
+ t .Run (tt .name , func (t * testing.T ) {
2499
+ a := & DefaultApiService {
2500
+ client : tt .fields .client ,
2501
+ }
2502
+ got , err := a .GetBranches (tt .args .project , tt .args .repository , tt .args .localVarOptionals )
2503
+ if (err != nil ) != tt .wantErr {
2504
+ t .Errorf ("DefaultApiService.GetBranches() error = %v, wantErr %v" , err , tt .wantErr )
2505
+ return
2506
+ }
2507
+ if got != nil {
2508
+ got .Response = nil
2509
+ }
2510
+ gotBranch := getBranch (got )
2511
+ if ! reflect .DeepEqual (gotBranch , tt .wantBranch ) {
2512
+ t .Errorf ("DefaultApiService.GetBranches() = branch: %v, want branch: %v" , gotBranch , tt .wantBranch )
2513
+ }
2514
+ })
2515
+ }
2516
+ }
2517
+
2391
2518
func TestDefaultApiService_GetBranchesPagination (t * testing.T ) {
2392
2519
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
2393
2520
w .Header ().Set ("Content-Type" , "application/json" )
0 commit comments