mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-04-04 08:50:13 -05:00
feat: add GetBranchResponse
Parse a single Branch from an APIResponse Useful in combination with the GetDefaultBranch API call
This commit is contained in:
parent
dff2223ade
commit
4d3afe3c12
@ -554,6 +554,13 @@ func GetBranchesResponse(r *APIResponse) ([]Branch, error) {
|
|||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBrancheResponse cast Branch into structure
|
||||||
|
func GetBranchResponse(r *APIResponse) (Branch, error) {
|
||||||
|
var m Branch
|
||||||
|
err := mapstructure.Decode(r.Values, &m)
|
||||||
|
return m, err
|
||||||
|
}
|
||||||
|
|
||||||
// GetRepositoriesResponse cast Repositories into structure
|
// GetRepositoriesResponse cast Repositories into structure
|
||||||
func GetRepositoriesResponse(r *APIResponse) ([]Repository, error) {
|
func GetRepositoriesResponse(r *APIResponse) ([]Repository, error) {
|
||||||
var m []Repository
|
var m []Repository
|
||||||
|
@ -115,6 +115,55 @@ func TestGetBranchesResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetBranchResponse(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
r *APIResponse
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want Branch
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Single branch",
|
||||||
|
args: args{
|
||||||
|
r: &APIResponse{
|
||||||
|
Values: map[string]interface{}{
|
||||||
|
"id": "refs/heads/main",
|
||||||
|
"displayId": "main",
|
||||||
|
"type": "BRANCH",
|
||||||
|
"latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13",
|
||||||
|
"latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13",
|
||||||
|
"isDefault": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: Branch{
|
||||||
|
ID: "refs/heads/main",
|
||||||
|
DisplayID: "main",
|
||||||
|
Type: "BRANCH",
|
||||||
|
LatestCommit: "8d51122def5632836d1cb1026e879069e10a1e13",
|
||||||
|
LatestChangeset: "8d51122def5632836d1cb1026e879069e10a1e13",
|
||||||
|
IsDefault: true,
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := GetBranchResponse(tt.args.r)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("GetBranchResponse() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("GetBranchResponse() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetRepositoriesResponse(t *testing.T) {
|
func TestGetRepositoriesResponse(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
r *APIResponse
|
r *APIResponse
|
||||||
|
Loading…
x
Reference in New Issue
Block a user