mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-04-12 04:08:06 -05:00
Merge pull request #39 from mpreu/bugfix/GetUsersWithAnyPermission
Fix missing options for GetUsersWithAnyPermission
This commit is contained in:
commit
6b375ee273
@ -5,8 +5,8 @@
|
|||||||
package bitbucketv1
|
package bitbucketv1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -105,6 +105,12 @@ type UserWithMetadata struct {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserPermission contains a user with its permission
|
||||||
|
type UserPermission struct {
|
||||||
|
User User `json:"user"`
|
||||||
|
Permission string `json:"permission"`
|
||||||
|
}
|
||||||
|
|
||||||
type MergeResult struct {
|
type MergeResult struct {
|
||||||
Outcome string `json:"outcome"`
|
Outcome string `json:"outcome"`
|
||||||
Current bool `json:"current"`
|
Current bool `json:"current"`
|
||||||
@ -275,16 +281,16 @@ type Content struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WebhookConfiguration struct {
|
type WebhookConfiguration struct {
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Events []string `json:"events"`
|
Events []string `json:"events"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
Configuration WebhookConfiguration `json:"configuration"`
|
Configuration WebhookConfiguration `json:"configuration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *SSHKey) String() string {
|
func (k *SSHKey) String() string {
|
||||||
@ -356,6 +362,13 @@ func GetContentResponse(r *APIResponse) (Content, error) {
|
|||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsersPermissionResponse casts user permissions into structure
|
||||||
|
func GetUsersPermissionResponse(r *APIResponse) ([]UserPermission, error) {
|
||||||
|
var c []UserPermission
|
||||||
|
err := mapstructure.Decode(r.Values["values"], &c)
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
|
||||||
// GetWebhooksResponse cast Webhooks into structure
|
// GetWebhooksResponse cast Webhooks into structure
|
||||||
func GetWebhooksResponse(r *APIResponse) ([]Webhook, error) {
|
func GetWebhooksResponse(r *APIResponse) ([]Webhook, error) {
|
||||||
var h []Webhook
|
var h []Webhook
|
||||||
|
@ -233,10 +233,10 @@ func TestGetWebhooksResponse(t *testing.T) {
|
|||||||
name: "Empty list",
|
name: "Empty list",
|
||||||
args: args{
|
args: args{
|
||||||
r: &APIResponse{
|
r: &APIResponse{
|
||||||
Values: map[string]interface{}{ "values": []interface{}{} },
|
Values: map[string]interface{}{"values": []interface{}{}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []Webhook{},
|
want: []Webhook{},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -245,11 +245,11 @@ func TestGetWebhooksResponse(t *testing.T) {
|
|||||||
r: &APIResponse{
|
r: &APIResponse{
|
||||||
Values: map[string]interface{}{
|
Values: map[string]interface{}{
|
||||||
"values": []interface{}{map[string]interface{}{
|
"values": []interface{}{map[string]interface{}{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "foo",
|
"name": "foo",
|
||||||
"url": "http://bitbucket.localhost/hook",
|
"url": "http://bitbucket.localhost/hook",
|
||||||
"active": false,
|
"active": false,
|
||||||
"events": []string{ "repo:modified" },
|
"events": []string{"repo:modified"},
|
||||||
"configuration": map[string]interface{}{
|
"configuration": map[string]interface{}{
|
||||||
"secret": "password",
|
"secret": "password",
|
||||||
},
|
},
|
||||||
@ -259,11 +259,11 @@ func TestGetWebhooksResponse(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: []Webhook{
|
want: []Webhook{
|
||||||
Webhook{
|
Webhook{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Url: "http://bitbucket.localhost/hook",
|
Url: "http://bitbucket.localhost/hook",
|
||||||
Active: false,
|
Active: false,
|
||||||
Events: []string{ "repo:modified" },
|
Events: []string{"repo:modified"},
|
||||||
Configuration: WebhookConfiguration{
|
Configuration: WebhookConfiguration{
|
||||||
Secret: "password",
|
Secret: "password",
|
||||||
},
|
},
|
||||||
@ -275,10 +275,10 @@ func TestGetWebhooksResponse(t *testing.T) {
|
|||||||
name: "Bad response",
|
name: "Bad response",
|
||||||
args: args{
|
args: args{
|
||||||
r: &APIResponse{
|
r: &APIResponse{
|
||||||
Values: map[string]interface{}{ "values": "not an array" },
|
Values: map[string]interface{}{"values": "not an array"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -296,6 +296,90 @@ func TestGetWebhooksResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: "REPO_ADMIN",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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 TestNewAPIResponse(t *testing.T) {
|
func TestNewAPIResponse(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
r *http.Response
|
r *http.Response
|
||||||
|
@ -7721,7 +7721,7 @@ func (a *DefaultApiService) GetUsersWithAnyPermission(localVarOptionals map[stri
|
|||||||
@param optional (nil or map[string]interface{}) with one or more of:
|
@param optional (nil or map[string]interface{}) with one or more of:
|
||||||
@param "filter" (string) if specified only group names containing the supplied string will be returned
|
@param "filter" (string) if specified only group names containing the supplied string will be returned
|
||||||
@return */
|
@return */
|
||||||
func (a *DefaultApiService) GetUsersWithAnyPermission_23(localVarOptionals map[string]interface{}) (*APIResponse, error) {
|
func (a *DefaultApiService) GetUsersWithAnyPermission_23(projectKey string, localVarOptionals map[string]interface{}) (*APIResponse, error) {
|
||||||
var (
|
var (
|
||||||
localVarHTTPMethod = strings.ToUpper("Get")
|
localVarHTTPMethod = strings.ToUpper("Get")
|
||||||
localVarPostBody interface{}
|
localVarPostBody interface{}
|
||||||
@ -7731,6 +7731,7 @@ func (a *DefaultApiService) GetUsersWithAnyPermission_23(localVarOptionals map[s
|
|||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/permissions/users"
|
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/permissions/users"
|
||||||
|
localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
|
||||||
|
|
||||||
localVarHeaderParams := make(map[string]string)
|
localVarHeaderParams := make(map[string]string)
|
||||||
localVarQueryParams := url.Values{}
|
localVarQueryParams := url.Values{}
|
||||||
@ -7784,7 +7785,7 @@ func (a *DefaultApiService) GetUsersWithAnyPermission_23(localVarOptionals map[s
|
|||||||
@param optional (nil or map[string]interface{}) with one or more of:
|
@param optional (nil or map[string]interface{}) with one or more of:
|
||||||
@param "filter" (string) if specified only group names containing the supplied string will be returned
|
@param "filter" (string) if specified only group names containing the supplied string will be returned
|
||||||
@return */
|
@return */
|
||||||
func (a *DefaultApiService) GetUsersWithAnyPermission_24(localVarOptionals map[string]interface{}) (*APIResponse, error) {
|
func (a *DefaultApiService) GetUsersWithAnyPermission_24(projectKey string, repositorySlug string, localVarOptionals map[string]interface{}) (*APIResponse, error) {
|
||||||
var (
|
var (
|
||||||
localVarHTTPMethod = strings.ToUpper("Get")
|
localVarHTTPMethod = strings.ToUpper("Get")
|
||||||
localVarPostBody interface{}
|
localVarPostBody interface{}
|
||||||
@ -7794,6 +7795,8 @@ func (a *DefaultApiService) GetUsersWithAnyPermission_24(localVarOptionals map[s
|
|||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/users"
|
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/users"
|
||||||
|
localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
|
||||||
|
localVarPath = strings.Replace(localVarPath, "{"+"repositorySlug"+"}", fmt.Sprintf("%v", repositorySlug), -1)
|
||||||
|
|
||||||
localVarHeaderParams := make(map[string]string)
|
localVarHeaderParams := make(map[string]string)
|
||||||
localVarQueryParams := url.Values{}
|
localVarQueryParams := url.Values{}
|
||||||
|
@ -4200,6 +4200,7 @@ func TestDefaultApiService_GetUsersWithAnyPermission_23(t *testing.T) {
|
|||||||
client *APIClient
|
client *APIClient
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
|
projectKey string
|
||||||
localVarOptionals map[string]interface{}
|
localVarOptionals map[string]interface{}
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -4209,14 +4210,14 @@ func TestDefaultApiService_GetUsersWithAnyPermission_23(t *testing.T) {
|
|||||||
want *APIResponse
|
want *APIResponse
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects/%7BprojectKey%7D/permissions/users: context canceled"}, true},
|
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects//permissions/users: context canceled"}, true},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
a := &DefaultApiService{
|
a := &DefaultApiService{
|
||||||
client: tt.fields.client,
|
client: tt.fields.client,
|
||||||
}
|
}
|
||||||
got, err := a.GetUsersWithAnyPermission_23(tt.args.localVarOptionals)
|
got, err := a.GetUsersWithAnyPermission_23(tt.args.projectKey, tt.args.localVarOptionals)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("DefaultApiService.GetUsersWithAnyPermission_23() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("DefaultApiService.GetUsersWithAnyPermission_23() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
@ -4233,6 +4234,8 @@ func TestDefaultApiService_GetUsersWithAnyPermission_24(t *testing.T) {
|
|||||||
client *APIClient
|
client *APIClient
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
|
projectKey string
|
||||||
|
repositorySlug string
|
||||||
localVarOptionals map[string]interface{}
|
localVarOptionals map[string]interface{}
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -4242,14 +4245,14 @@ func TestDefaultApiService_GetUsersWithAnyPermission_24(t *testing.T) {
|
|||||||
want *APIResponse
|
want *APIResponse
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects/%7BprojectKey%7D/repos/%7BrepositorySlug%7D/permissions/users: context canceled"}, true},
|
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects//repos//permissions/users: context canceled"}, true},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
a := &DefaultApiService{
|
a := &DefaultApiService{
|
||||||
client: tt.fields.client,
|
client: tt.fields.client,
|
||||||
}
|
}
|
||||||
got, err := a.GetUsersWithAnyPermission_24(tt.args.localVarOptionals)
|
got, err := a.GetUsersWithAnyPermission_24(tt.args.projectKey, tt.args.repositorySlug, tt.args.localVarOptionals)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("DefaultApiService.GetUsersWithAnyPermission_24() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("DefaultApiService.GetUsersWithAnyPermission_24() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user