Skip to content

Commit 2a8e7c0

Browse files
author
Daniel Steinke
committed
Add testcases for group and project iterations
Added missing registration of services.
1 parent fc4f5cd commit 2a8e7c0

6 files changed

+125
-3
lines changed

gitlab.go

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ type Client struct {
131131
GroupCluster *GroupClustersService
132132
GroupImportExport *GroupImportExportService
133133
GroupIssueBoards *GroupIssueBoardsService
134+
GroupIterations *GroupIterationsService
134135
GroupLabels *GroupLabelsService
135136
GroupMembers *GroupMembersService
136137
GroupMilestones *GroupMilestonesService
@@ -167,6 +168,7 @@ type Client struct {
167168
ProjectAccessTokens *ProjectAccessTokensService
168169
ProjectCluster *ProjectClustersService
169170
ProjectImportExport *ProjectImportExportService
171+
ProjectIterations *ProjectIterationsService
170172
ProjectMembers *ProjectMembersService
171173
ProjectMirrors *ProjectMirrorService
172174
ProjectSnippets *ProjectSnippetsService
@@ -325,6 +327,7 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {
325327
c.GroupCluster = &GroupClustersService{client: c}
326328
c.GroupImportExport = &GroupImportExportService{client: c}
327329
c.GroupIssueBoards = &GroupIssueBoardsService{client: c}
330+
c.GroupIterations = &GroupIterationsService{client: c}
328331
c.GroupLabels = &GroupLabelsService{client: c}
329332
c.GroupMembers = &GroupMembersService{client: c}
330333
c.GroupMilestones = &GroupMilestonesService{client: c}
@@ -361,6 +364,7 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {
361364
c.ProjectAccessTokens = &ProjectAccessTokensService{client: c}
362365
c.ProjectCluster = &ProjectClustersService{client: c}
363366
c.ProjectImportExport = &ProjectImportExportService{client: c}
367+
c.ProjectIterations = &ProjectIterationsService{client: c}
364368
c.ProjectMembers = &ProjectMembersService{client: c}
365369
c.ProjectMirrors = &ProjectMirrorService{client: c}
366370
c.ProjectSnippets = &ProjectSnippetsService{client: c}

group_iterations.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type GroupIterationsService struct {
3838
type GroupIteration struct {
3939
ID int `json:"id"`
4040
IID int `json:"iid"`
41+
Sequence int `json:"sequence"`
4142
GroupID int `json:"group_id"`
4243
Title string `json:"title"`
4344
Description string `json:"description"`

group_iterations_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package gitlab
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"reflect"
7+
"testing"
8+
)
9+
10+
func TestListGroupIterations(t *testing.T) {
11+
mux, server, client := setup(t)
12+
defer teardown(server)
13+
14+
mux.HandleFunc("/api/v4/groups/5/iterations",
15+
func(w http.ResponseWriter, r *http.Request) {
16+
testMethod(t, r, http.MethodGet)
17+
fmt.Fprintf(w, `[{
18+
"id": 53,
19+
"iid": 13,
20+
"sequence": 1,
21+
"group_id": 5,
22+
"title": "Iteration II",
23+
"description": "Ipsum Lorem ipsum",
24+
"state": 2,
25+
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
26+
}
27+
]`)
28+
})
29+
30+
iterations, _, err := client.GroupIterations.ListGroupIterations(5, &ListGroupIterationsOptions{})
31+
if err != nil {
32+
t.Errorf("GroupIterations.ListGroupIterations returned error: %v", err)
33+
}
34+
35+
want := []*GroupIteration{{
36+
ID: 53,
37+
IID: 13,
38+
Sequence: 1,
39+
GroupID: 5,
40+
Title: "Iteration II",
41+
Description: "Ipsum Lorem ipsum",
42+
State: 2,
43+
WebURL: "http://gitlab.example.com/groups/my-group/-/iterations/13",
44+
}}
45+
if !reflect.DeepEqual(want, iterations) {
46+
t.Errorf("GroupIterations.ListGroupIterations returned %+v, want %+v", iterations, want)
47+
}
48+
}

iterations.go renamed to project_iterations.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ import (
2727
//
2828
// GitLab API docs: https://docs.gitlab.com/ee/api/iterations.html
2929

30-
type IterationsService struct {
30+
type ProjectIterationsService struct {
3131
client *Client
3232
}
3333

34+
// Iteration represents a GitLab iteration
35+
//
36+
// GitLab API docs: https://docs.gitlab.com/ee/api/iterations.html
37+
// CAVEAT: GitLab docu currently misses `sequence` key.
3438
type Iteration struct {
3539
ID int `json:"id"`
3640
IID int `json:"iid"`
41+
Sequence int `json:"sequence"`
3742
GroupID int `json:"group_id"`
3843
Title string `json:"title"`
3944
Description string `json:"description"`
@@ -61,10 +66,10 @@ type ListProjectIterationsOptions struct {
6166
}
6267

6368
//ListProjectIterations lists all iterations of the projects ancestor groups.
64-
//As of GitLab 13.5, there are not direct project-level iterations.
69+
//As of GitLab 13.5, there are no direct project-level iterations.
6570

6671
// GitLab API docs: https://docs.gitlab.com/ee/api/iterations.html
67-
func (i *IterationsService) ListProjectIterations(pid interface{}, opt *ListGroupProjectsOptions, options ...RequestOptionFunc) ([]*Iteration, *Response, error) {
72+
func (i *ProjectIterationsService) ListProjectIterations(pid interface{}, opt *ListProjectIterationsOptions, options ...RequestOptionFunc) ([]*Iteration, *Response, error) {
6873
project, err := parseID(pid)
6974
if err != nil {
7075
return nil, nil, err

project_iterations_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package gitlab
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"reflect"
7+
"testing"
8+
)
9+
10+
func TestListProjectIterations(t *testing.T) {
11+
mux, server, client := setup(t)
12+
defer teardown(server)
13+
14+
mux.HandleFunc("/api/v4/projects/42/iterations",
15+
func(w http.ResponseWriter, r *http.Request) {
16+
testMethod(t, r, http.MethodGet)
17+
fmt.Fprintf(w, `[{
18+
"id": 53,
19+
"iid": 13,
20+
"sequence": 1,
21+
"group_id": 5,
22+
"title": "Iteration II",
23+
"description": "Ipsum Lorem ipsum",
24+
"state": 2,
25+
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
26+
}
27+
]`)
28+
})
29+
30+
iterations, _, err := client.ProjectIterations.ListProjectIterations(42, &ListProjectIterationsOptions{})
31+
if err != nil {
32+
t.Errorf("GroupIterations.ListGroupIterations returned error: %v", err)
33+
}
34+
35+
want := []*Iteration{{
36+
ID: 53,
37+
IID: 13,
38+
Sequence: 1,
39+
GroupID: 5,
40+
Title: "Iteration II",
41+
Description: "Ipsum Lorem ipsum",
42+
State: 2,
43+
WebURL: "http://gitlab.example.com/groups/my-group/-/iterations/13",
44+
}}
45+
if !reflect.DeepEqual(want, iterations) {
46+
t.Errorf("ProjectIterations.ListProjectIterations returned %+v, want %+v", iterations, want)
47+
}
48+
}

testdata/list_group_iterations.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"id": 53,
4+
"iid": 13,
5+
"sequence": 1,
6+
"group_id": 5,
7+
"title": "Iteration II",
8+
"description": "Ipsum Lorem ipsum",
9+
"state": 2,
10+
"created_at": "2020-01-27T05:07:12.573Z",
11+
"updated_at": "2020-01-27T05:07:12.573Z",
12+
"due_date": "2020-02-01",
13+
"start_date": "2020-02-14",
14+
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
15+
}
16+
]

0 commit comments

Comments
 (0)