forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojects_test.go
163 lines (134 loc) · 4.1 KB
/
projects_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestListProjects(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{
ListOptions: ListOptions{2, 3},
Archived: Bool(true),
OrderBy: String("name"),
Sort: String("asc"),
Search: String("query"),
Simple: Bool(true),
Visibility: Visibility(PublicVisibility),
}
projects, _, err := client.Projects.ListProjects(opt)
if err != nil {
t.Errorf("Projects.ListProjects returned error: %v", err)
}
want := []*Project{{ID: 1}, {ID: 2}}
if !reflect.DeepEqual(want, projects) {
t.Errorf("Projects.ListProjects returned %+v, want %+v", projects, want)
}
}
func TestListOwnedProjects(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{
ListOptions: ListOptions{2, 3},
Archived: Bool(true),
OrderBy: String("name"),
Sort: String("asc"),
Search: String("query"),
Simple: Bool(true),
Owned: Bool(true),
Visibility: Visibility(PublicVisibility),
}
projects, _, err := client.Projects.ListProjects(opt)
if err != nil {
t.Errorf("Projects.ListOwnedProjects returned error: %v", err)
}
want := []*Project{{ID: 1}, {ID: 2}}
if !reflect.DeepEqual(want, projects) {
t.Errorf("Projects.ListOwnedProjects returned %+v, want %+v", projects, want)
}
}
func TestListStarredProjects(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{
ListOptions: ListOptions{2, 3},
Archived: Bool(true),
OrderBy: String("name"),
Sort: String("asc"),
Search: String("query"),
Simple: Bool(true),
Starred: Bool(true),
Visibility: Visibility(PublicVisibility),
}
projects, _, err := client.Projects.ListProjects(opt)
if err != nil {
t.Errorf("Projects.ListStarredProjects returned error: %v", err)
}
want := []*Project{{ID: 1}, {ID: 2}}
if !reflect.DeepEqual(want, projects) {
t.Errorf("Projects.ListStarredProjects returned %+v, want %+v", projects, want)
}
}
func TestGetProject_byID(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
want := &Project{ID: 1}
project, _, err := client.Projects.GetProject(1)
if err != nil {
t.Fatalf("Projects.GetProject returns an error: %v", err)
}
if !reflect.DeepEqual(want, project) {
t.Errorf("Projects.GetProject returned %+v, want %+v", project, want)
}
}
func TestGetProject_byName(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/", func(w http.ResponseWriter, r *http.Request) {
testURL(t, r, "/projects/namespace%2Fname")
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1}`)
})
want := &Project{ID: 1}
project, _, err := client.Projects.GetProject("namespace/name")
if err != nil {
t.Fatalf("Projects.GetProject returns an error: %v", err)
}
if !reflect.DeepEqual(want, project) {
t.Errorf("Projects.GetProject returned %+v, want %+v", project, want)
}
}
func TestCreateProject(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, `{"id":1}`)
})
opt := &CreateProjectOptions{Name: String("n")}
project, _, err := client.Projects.CreateProject(opt)
if err != nil {
t.Errorf("Projects.CreateProject returned error: %v", err)
}
want := &Project{ID: 1}
if !reflect.DeepEqual(want, project) {
t.Errorf("Projects.CreateProject returned %+v, want %+v", project, want)
}
}