Merge pull request #68 from mlosicki/bugfix/get-branches-no-pagination

fix: support pagination for GetBranches
This commit is contained in:
George Fleury 2022-01-25 10:25:02 -03:00 committed by GitHub
commit 90a950f9bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 0 deletions

View File

@ -3260,7 +3260,19 @@ func (a *DefaultApiService) GetBranches(project, repository string, localVarOpti
if err := typeCheckParameter(localVarOptionals["orderBy"], "string", "orderBy"); err != nil {
return nil, err
}
if err := typeCheckParameter(localVarOptionals["limit"], "int", "limit"); err != nil {
return nil, err
}
if err := typeCheckParameter(localVarOptionals["start"], "int", "start"); err != nil {
return nil, err
}
if localVarTempParam, localVarOk := localVarOptionals["limit"].(int); localVarOk {
localVarQueryParams.Add("limit", parameterToString(localVarTempParam, ""))
}
if localVarTempParam, localVarOk := localVarOptionals["start"].(int); localVarOk {
localVarQueryParams.Add("start", parameterToString(localVarTempParam, ""))
}
if localVarTempParam, localVarOk := localVarOptionals["base"].(string); localVarOk {
localVarQueryParams.Add("base", parameterToString(localVarTempParam, ""))
}

View File

@ -5,6 +5,9 @@
package bitbucketv1
import (
"io"
"net/http"
"net/http/httptest"
"os"
"reflect"
"testing"
@ -2331,6 +2334,89 @@ func TestDefaultApiService_GetBranches(t *testing.T) {
}
}
func TestDefaultApiService_GetBranchesPagination(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch r.RequestURI {
case "/api/1.0/projects/PROJECT/repos/REPO/branches?limit=100&start=0":
_, err := io.WriteString(w, `{
"size": 1,
"limit": 100,
"isLastPage": true,
"values": [
{
"id": "refs/heads/main",
"displayId": "main",
"type": "BRANCH",
"latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13",
"latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13",
"isDefault": true
}
],
"start": 0
}`)
if err != nil {
t.Errorf("DefaultApiService.GetBranches() error = i/o error %v", err)
}
default:
t.Errorf("DefaultApiService.GetBranches() error = unhandled request %s", r.RequestURI)
}
}))
defer ts.Close()
client := NewAPIClient(
context.TODO(),
NewConfiguration(ts.URL),
)
type fields struct {
client *APIClient
}
type args struct {
project string
repository string
localVarOptionals map[string]interface{}
}
tests := []struct {
name string
fields fields
args args
want *APIResponse
wantErr, integrationTest bool
}{
{"limitAndStartSet", fields{client: client}, args{
project: "PROJECT", repository: "REPO",
localVarOptionals: map[string]interface{}{
"limit": 100,
"start": 0,
}}, nil, false, false},
{"incorrectLimit", fields{client: client}, args{
project: "PROJECT", repository: "REPO",
localVarOptionals: map[string]interface{}{
"limit": "wrong",
}}, nil, true, false},
{"incorrectStart", fields{client: client}, args{
project: "PROJECT", repository: "REPO",
localVarOptionals: map[string]interface{}{
"start": "wrong",
}}, nil, true, false},
}
for _, tt := range tests {
if tt.integrationTest != runIntegrationTests {
continue
}
t.Run(tt.name, func(t *testing.T) {
a := &DefaultApiService{
client: tt.fields.client,
}
_, err := a.GetBranches(tt.args.project, tt.args.repository, tt.args.localVarOptionals)
if (err != nil) != tt.wantErr {
t.Errorf("DefaultApiService.GetBranches() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
func TestDefaultApiService_GetChanges(t *testing.T) {
type fields struct {
client *APIClient