forked from andygrunwald/go-jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissionschemes_test.go
106 lines (95 loc) · 2.87 KB
/
permissionschemes_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
package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestPermissionSchemeService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/3/permissionscheme"
raw, err := ioutil.ReadFile("./mocks/all_permissionschemes.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, string(raw))
})
permissionScheme, _, err := testClient.PermissionScheme.GetList()
if err != nil {
t.Errorf("Error given: %v", err)
}
if permissionScheme == nil {
t.Error("Expected permissionScheme list. PermissionScheme list is nil")
return
}
if len(permissionScheme.PermissionSchemes) != 2 {
t.Errorf("Expected %d permissionSchemes but got %d", 2, len(permissionScheme.PermissionSchemes))
}
}
func TestPermissionSchemeService_GetList_NoList(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/3/permissionscheme"
raw, err := ioutil.ReadFile("./mocks/no_permissionschemes.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEndpoint, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, testAPIEndpoint)
fmt.Fprint(w, string(raw))
})
permissionScheme, _, err := testClient.PermissionScheme.GetList()
if permissionScheme != nil {
t.Errorf("Expected permissionScheme list has %d entries but should be nil", len(permissionScheme.PermissionSchemes))
}
if err == nil {
t.Errorf("No error given")
}
}
func TestPermissionSchemeService_Get(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/3/permissionscheme/10100"
raw, err := ioutil.ReadFile("./mocks/permissionscheme.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEdpoint)
fmt.Fprint(writer, string(raw))
})
permissionScheme, _, err := testClient.PermissionScheme.Get(10100)
if permissionScheme == nil {
t.Errorf("Expected permissionscheme, got nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestPermissionSchemeService_Get_NoScheme(t *testing.T) {
setup()
defer teardown()
testAPIEdpoint := "/rest/api/3/permissionscheme/99999"
raw, err := ioutil.ReadFile("./mocks/no_permissionscheme.json")
if err != nil {
t.Error(err.Error())
}
testMux.HandleFunc(testAPIEdpoint, func(writer http.ResponseWriter, request *http.Request) {
testMethod(t, request, "GET")
testRequestURL(t, request, testAPIEdpoint)
fmt.Fprint(writer, string(raw))
})
permissionScheme, _, err := testClient.PermissionScheme.Get(99999)
if permissionScheme != nil {
t.Errorf("Expected nil, got permissionschme %v", permissionScheme)
}
if err == nil {
t.Errorf("No error given")
}
}