Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
13525b17
Commit
13525b17
authored
Jun 05, 2018
by
JB Sazon
Committed by
Sander van Harmelen
Jun 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue 414 for TransferGroup. Add tests for Groups (#415)
parent
e519e706
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
187 additions
and
13 deletions
+187
-13
groups.go
groups.go
+9
-2
groups_test.go
groups_test.go
+178
-11
No files found.
groups.go
View file @
13525b17
...
...
@@ -142,12 +142,19 @@ func (s *GroupsService) CreateGroup(opt *CreateGroupOptions, options ...OptionFu
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#transfer-project-to-group
func
(
s
*
GroupsService
)
TransferGroup
(
gid
interface
{},
p
roject
int
,
options
...
OptionFunc
)
(
*
Group
,
*
Response
,
error
)
{
func
(
s
*
GroupsService
)
TransferGroup
(
gid
interface
{},
p
id
interface
{}
,
options
...
OptionFunc
)
(
*
Group
,
*
Response
,
error
)
{
group
,
err
:=
parseID
(
gid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"groups/%s/projects/%d"
,
url
.
QueryEscape
(
group
),
project
)
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"groups/%s/projects/%s"
,
url
.
QueryEscape
(
group
),
url
.
QueryEscape
(
project
))
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
if
err
!=
nil
{
...
...
groups_test.go
View file @
13525b17
...
...
@@ -7,27 +7,173 @@ import (
"testing"
)
func
TestListGroup
Project
s
(
t
*
testing
.
T
)
{
func
TestListGroups
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups
/22/projects
"
,
mux
.
HandleFunc
(
"/api/v4/groups"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`[{"id":1},{"id":2}]`
)
})
opt
:=
&
ListGroupProjectsOptions
{
ListOptions
:
ListOptions
{
2
,
3
},
Archived
:
Bool
(
true
),
OrderBy
:
String
(
"name"
),
Sort
:
String
(
"asc"
),
Search
:
String
(
"query"
),
Simple
:
Bool
(
true
),
Visibility
:
Visibility
(
PublicVisibility
),
groups
,
_
,
err
:=
client
.
Groups
.
ListGroups
(
&
ListGroupsOptions
{})
if
err
!=
nil
{
t
.
Errorf
(
"Groups.ListGroups returned error: %v"
,
err
)
}
want
:=
[]
*
Group
{{
ID
:
1
},
{
ID
:
2
}}
if
!
reflect
.
DeepEqual
(
want
,
groups
)
{
t
.
Errorf
(
"Groups.ListGroups returned %+v, want %+v"
,
groups
,
want
)
}
}
func
TestGetGroup
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups/g"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`{"id": 1, "name": "g"}`
)
})
group
,
_
,
err
:=
client
.
Groups
.
GetGroup
(
"g"
)
if
err
!=
nil
{
t
.
Errorf
(
"Groups.GetGroup returned error: %v"
,
err
)
}
want
:=
&
Group
{
ID
:
1
,
Name
:
"g"
}
if
!
reflect
.
DeepEqual
(
want
,
group
)
{
t
.
Errorf
(
"Groups.GetGroup returned %+v, want %+v"
,
group
,
want
)
}
}
func
TestCreateGroup
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
fmt
.
Fprint
(
w
,
`{"id": 1, "name": "g", "path": "g"}`
)
})
opt
:=
&
CreateGroupOptions
{
Name
:
String
(
"g"
),
Path
:
String
(
"g"
),
}
group
,
_
,
err
:=
client
.
Groups
.
CreateGroup
(
opt
,
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"Groups.CreateGroup returned error: %v"
,
err
)
}
want
:=
&
Group
{
ID
:
1
,
Name
:
"g"
,
Path
:
"g"
}
if
!
reflect
.
DeepEqual
(
want
,
group
)
{
t
.
Errorf
(
"Groups.CreateGroup returned %+v, want %+v"
,
group
,
want
)
}
}
func
TestTransferGroup
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups/1/projects/2"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
fmt
.
Fprintf
(
w
,
`{"id": 1}`
)
})
group
,
_
,
err
:=
client
.
Groups
.
TransferGroup
(
1
,
2
)
if
err
!=
nil
{
t
.
Errorf
(
"Groups.TransferGroup returned error: %v"
,
err
)
}
want
:=
&
Group
{
ID
:
1
}
if
!
reflect
.
DeepEqual
(
group
,
want
)
{
t
.
Errorf
(
"Groups.TransferGroup returned %+v, want %+v"
,
group
,
want
)
}
}
func
TestDeleteGroup
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups/1"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"DELETE"
)
w
.
WriteHeader
(
http
.
StatusAccepted
)
})
resp
,
err
:=
client
.
Groups
.
DeleteGroup
(
1
)
if
err
!=
nil
{
t
.
Errorf
(
"Groups.DeleteGroup returned error: %v"
,
err
)
}
fmt
.
Println
(
resp
.
StatusCode
)
want
:=
http
.
StatusAccepted
got
:=
resp
.
StatusCode
if
got
!=
want
{
t
.
Errorf
(
"Groups.DeleteGroup returned %d, want %d"
,
got
,
want
)
}
}
func
TestSearchGroup
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
projects
,
_
,
err
:=
client
.
Groups
.
ListGroupProjects
(
22
,
opt
)
mux
.
HandleFunc
(
"/api/v4/groups"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`[{"id": 1, "name": "Foobar Group"}]`
)
})
groups
,
_
,
err
:=
client
.
Groups
.
SearchGroup
(
"foobar"
)
if
err
!=
nil
{
t
.
Errorf
(
"Groups.SearchGroup returned error: %v"
,
err
)
}
want
:=
[]
*
Group
{{
ID
:
1
,
Name
:
"Foobar Group"
}}
if
!
reflect
.
DeepEqual
(
want
,
groups
)
{
t
.
Errorf
(
"Groups.SearchGroup returned +%v, want %+v"
,
groups
,
want
)
}
}
func
TestUpdateGroup
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups/1"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"PUT"
)
fmt
.
Fprint
(
w
,
`{"id": 1}`
)
})
group
,
_
,
err
:=
client
.
Groups
.
UpdateGroup
(
1
,
&
UpdateGroupOptions
{})
if
err
!=
nil
{
t
.
Errorf
(
"Groups.UpdateGroup returned error: %v"
,
err
)
}
want
:=
&
Group
{
ID
:
1
}
if
!
reflect
.
DeepEqual
(
want
,
group
)
{
t
.
Errorf
(
"Groups.UpdatedGroup returned %+v, want %+v"
,
group
,
want
)
}
}
func
TestListGroupProjects
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups/22/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`[{"id":1},{"id":2}]`
)
})
projects
,
_
,
err
:=
client
.
Groups
.
ListGroupProjects
(
22
,
&
ListGroupProjectsOptions
{})
if
err
!=
nil
{
t
.
Errorf
(
"Groups.ListGroupProjects returned error: %v"
,
err
)
}
...
...
@@ -37,3 +183,24 @@ func TestListGroupProjects(t *testing.T) {
t
.
Errorf
(
"Groups.ListGroupProjects returned %+v, want %+v"
,
projects
,
want
)
}
}
func
TestListSubgroups
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/groups/1/subgroups"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`[{"id": 1}, {"id": 2}]`
)
})
groups
,
_
,
err
:=
client
.
Groups
.
ListSubgroups
(
1
,
&
ListSubgroupsOptions
{})
if
err
!=
nil
{
t
.
Errorf
(
"Groups.ListSubgroups returned error: %v"
,
err
)
}
want
:=
[]
*
Group
{{
ID
:
1
},
{
ID
:
2
}}
if
!
reflect
.
DeepEqual
(
want
,
groups
)
{
t
.
Errorf
(
"Groups.ListSubgroups returned %+v, want %+v"
,
groups
,
want
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment