forked from andygrunwald/go-jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_test.go
158 lines (136 loc) · 4.01 KB
/
project_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
package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestProjectService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})
projects, _, err := testClient.Project.GetList()
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_ListWithOptions(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project"
raw, err := ioutil.ReadFile("./mocks/all_projects.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/project?expand=issueTypes")
fmt.Fprint(w, string(raw))
})
projects, _, err := testClient.Project.ListWithOptions(&GetQueryOptions{Expand: "issueTypes"})
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_Get(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/12310505"
raw, err := ioutil.ReadFile("./mocks/project.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, string(raw))
})
projects, _, err := testClient.Project.Get("12310505")
if projects == nil {
t.Error("Expected project list. Project list is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_Get_NoProject(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/99999999"
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, nil)
})
projects, resp, err := testClient.Project.Get("99999999")
if projects != nil {
t.Errorf("Expected nil. Got %+v", projects)
}
if resp.Status == "404" {
t.Errorf("Expected status 404. Got %s", resp.Status)
}
if err == nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_GetPermissionScheme_Failure(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/99999999/permissionscheme"
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, nil)
})
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
if permissionScheme != nil {
t.Errorf("Expected nil. Got %+v", permissionScheme)
}
if resp.Status == "404" {
t.Errorf("Expected status 404. Got %s", resp.Status)
}
if err == nil {
t.Errorf("Error given: %s", err)
}
}
func TestProjectService_GetPermissionScheme_Success(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/2/project/99999999/permissionscheme"
testMux.HandleFunc(testAPIEdpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEdpoint)
fmt.Fprint(w, `{
"expand": "permissions,user,group,projectRole,field,all",
"id": 10201,
"self": "https://www.example.com/rest/api/2/permissionscheme/10201",
"name": "Project for specific-users",
"description": "Projects that can only see for people belonging to specific-users group"
}`)
})
permissionScheme, resp, err := testClient.Project.GetPermissionScheme("99999999")
if permissionScheme.ID != 10201 {
t.Errorf("Expected Permission Scheme ID. Got %+v", permissionScheme)
}
if resp.Status == "404" {
t.Errorf("Expected status 404. Got %s", resp.Status)
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}