mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-04-05 17:28:05 -05:00

Reponse to extract groups and their permissions was added. Additional definitons for the avilable Bitbucket Server permission levels were added to allow for easier usage. Tests were added and udpated.
524 lines
11 KiB
Go
524 lines
11 KiB
Go
/*
|
|
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
|
*/
|
|
|
|
package bitbucketv1
|
|
|
|
import (
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestSSHKey_String(t *testing.T) {
|
|
type fields struct {
|
|
ID int
|
|
Text string
|
|
Label string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
want string
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
k := &SSHKey{
|
|
ID: tt.fields.ID,
|
|
Text: tt.fields.Text,
|
|
Label: tt.fields.Label,
|
|
}
|
|
if got := k.String(); got != tt.want {
|
|
t.Errorf("SSHKey.String() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetCommitsResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []Commit
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetCommitsResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetCommitsResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetCommitsResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetTagsResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []Tag
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetTagsResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetTagsResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetTagsResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetBranchesResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []Branch
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetBranchesResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetBranchesResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetBranchesResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetRepositoriesResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []Repository
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetRepositoriesResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetRepositoriesResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetRepositoriesResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetRepositoryResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want Repository
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetRepositoryResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetRepositoryResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetRepositoryResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetDiffResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want Diff
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetDiffResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetDiffResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetDiffResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetSSHKeysResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []SSHKey
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetSSHKeysResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetSSHKeysResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetSSHKeysResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetWebhooksResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []Webhook
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Empty list",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{"values": []interface{}{}},
|
|
},
|
|
},
|
|
want: []Webhook{},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "Single webhook",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{
|
|
"values": []interface{}{map[string]interface{}{
|
|
"id": 1,
|
|
"name": "foo",
|
|
"url": "http://bitbucket.localhost/hook",
|
|
"active": false,
|
|
"events": []string{"repo:modified"},
|
|
"configuration": map[string]interface{}{
|
|
"secret": "password",
|
|
},
|
|
}},
|
|
},
|
|
},
|
|
},
|
|
want: []Webhook{
|
|
Webhook{
|
|
ID: 1,
|
|
Name: "foo",
|
|
Url: "http://bitbucket.localhost/hook",
|
|
Active: false,
|
|
Events: []string{"repo:modified"},
|
|
Configuration: WebhookConfiguration{
|
|
Secret: "password",
|
|
},
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "Bad response",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{"values": "not an array"},
|
|
},
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetWebhooksResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GetWebhooksResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetWebhooksResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetUsersPermissionResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []UserPermission
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Empty list",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{"values": []interface{}{}},
|
|
},
|
|
},
|
|
want: []UserPermission{},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "Bad response",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{"values": "not an array"},
|
|
},
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "Single user permission",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{
|
|
"values": []interface{}{map[string]interface{}{
|
|
"user": map[string]interface{}{
|
|
"name": "jcitizen",
|
|
// TODO: This field should be emailAddress according to the REST API
|
|
// documentation, but is defined as Email in the User struct. Mapstruct #
|
|
// therefore only decodes this when reffered to as 'email', which is plain wrong.
|
|
// "email": "jane@example.com",
|
|
"id": 101,
|
|
"displayName": "Jane Citizen",
|
|
"active": true,
|
|
"slug": "jcitizen",
|
|
"type": "NORMAL",
|
|
},
|
|
"permission": "REPO_ADMIN",
|
|
}},
|
|
},
|
|
},
|
|
},
|
|
want: []UserPermission{
|
|
UserPermission{
|
|
User: User{
|
|
Name: "jcitizen",
|
|
// Email: "jane@example.com",
|
|
ID: 101,
|
|
DisplayName: "Jane Citizen",
|
|
Active: true,
|
|
Slug: "jcitizen",
|
|
Type: "NORMAL",
|
|
},
|
|
Permission: PermissionRepositoryAdmin.String(),
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetUsersPermissionResponse(tt.args.r)
|
|
if err != nil && !tt.wantErr {
|
|
t.Errorf("GetUsersPermissionResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetUsersPermissionResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetGroupsPermissionResponse(t *testing.T) {
|
|
type args struct {
|
|
r *APIResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []GroupPermission
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Empty list",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{"values": []interface{}{}},
|
|
},
|
|
},
|
|
want: []GroupPermission{},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "Bad response",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{"values": "not an array"},
|
|
},
|
|
},
|
|
want: nil,
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "Single group permission",
|
|
args: args{
|
|
r: &APIResponse{
|
|
Values: map[string]interface{}{
|
|
"values": []interface{}{map[string]interface{}{
|
|
"group": map[string]interface{}{
|
|
"name": "group1",
|
|
},
|
|
"permission": "REPO_ADMIN",
|
|
}},
|
|
},
|
|
},
|
|
},
|
|
want: []GroupPermission{
|
|
GroupPermission{
|
|
Group: Group{
|
|
Name: "group1",
|
|
},
|
|
Permission: PermissionRepositoryAdmin.String(),
|
|
},
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := GetGroupsPermissionResponse(tt.args.r)
|
|
if err != nil && !tt.wantErr {
|
|
t.Errorf("GetGroupsPermissionResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("GetGroupsPermissionResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewAPIResponse(t *testing.T) {
|
|
type args struct {
|
|
r *http.Response
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *APIResponse
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := NewAPIResponse(tt.args.r); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("NewAPIResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewAPIResponseWithError(t *testing.T) {
|
|
type args struct {
|
|
r *http.Response
|
|
err error
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *APIResponse
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NewAPIResponseWithError(tt.args.r, tt.args.err)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("NewAPIResponseWithError() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("NewAPIResponseWithError() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewBitbucketAPIResponse(t *testing.T) {
|
|
type args struct {
|
|
r *http.Response
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *APIResponse
|
|
wantErr bool
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := NewBitbucketAPIResponse(tt.args.r)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("NewBitbucketAPIResponse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("NewBitbucketAPIResponse() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|