mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-04-05 01:10:12 -05:00
Merge pull request #68 from mlosicki/bugfix/get-branches-no-pagination
fix: support pagination for GetBranches
This commit is contained in:
commit
90a950f9bc
@ -3260,7 +3260,19 @@ func (a *DefaultApiService) GetBranches(project, repository string, localVarOpti
|
|||||||
if err := typeCheckParameter(localVarOptionals["orderBy"], "string", "orderBy"); err != nil {
|
if err := typeCheckParameter(localVarOptionals["orderBy"], "string", "orderBy"); err != nil {
|
||||||
return nil, err
|
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 {
|
if localVarTempParam, localVarOk := localVarOptionals["base"].(string); localVarOk {
|
||||||
localVarQueryParams.Add("base", parameterToString(localVarTempParam, ""))
|
localVarQueryParams.Add("base", parameterToString(localVarTempParam, ""))
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
package bitbucketv1
|
package bitbucketv1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"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) {
|
func TestDefaultApiService_GetChanges(t *testing.T) {
|
||||||
type fields struct {
|
type fields struct {
|
||||||
client *APIClient
|
client *APIClient
|
||||||
|
Loading…
x
Reference in New Issue
Block a user