forked from andygrunwald/go-jira
-
Notifications
You must be signed in to change notification settings - Fork 1
/
issuelinktype_test.go
118 lines (100 loc) · 3.13 KB
/
issuelinktype_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
package jira
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
)
func TestIssueLinkTypeService_GetList(t *testing.T) {
setup()
defer teardown()
testAPIEndpoint := "/rest/api/2/issueLinkType"
raw, err := ioutil.ReadFile("./mocks/all_issuelinktypes.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))
})
linkTypes, _, err := testClient.IssueLinkType.GetList()
if linkTypes == nil {
t.Error("Expected issueLinkType list. LinkTypes is nil")
}
if err != nil {
t.Errorf("Error give: %s", err)
}
}
func TestIssueLinkTypeService_Get(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issueLinkType/123", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/issueLinkType/123")
fmt.Fprint(w, `{"id": "123","name": "Blocked","inward": "Blocked","outward": "Blocked",
"self": "https://www.example.com/jira/rest/api/2/issueLinkType/123"}`)
})
if linkType, _, err := testClient.IssueLinkType.Get("123"); err != nil {
t.Errorf("Error given: %s", err)
} else if linkType == nil {
t.Error("Expected linkType. LinkType is nil")
}
}
func TestIssueLinkTypeService_Create(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issueLinkType", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testRequestURL(t, r, "/rest/api/2/issueLinkType")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"id":"10021","name":"Problem/Incident","inward":"is caused by",
"outward":"causes","self":"https://www.example.com/jira/rest/api/2/issueLinkType/10021"}`)
})
lt := &IssueLinkType{
Name: "Problem/Incident",
Inward: "is caused by",
Outward: "causes",
}
if linkType, _, err := testClient.IssueLinkType.Create(lt); err != nil {
t.Errorf("Error given: %s", err)
} else if linkType == nil {
t.Error("Expected linkType. LinkType is nil")
}
}
func TestIssueLinkTypeService_Update(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issueLinkType/100", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testRequestURL(t, r, "/rest/api/2/issueLinkType/100")
w.WriteHeader(http.StatusNoContent)
})
lt := &IssueLinkType{
ID: "100",
Name: "Problem/Incident",
Inward: "is caused by",
Outward: "causes",
}
if linkType, _, err := testClient.IssueLinkType.Update(lt); err != nil {
t.Errorf("Error given: %s", err)
} else if linkType == nil {
t.Error("Expected linkType. LinkType is nil")
}
}
func TestIssueLinkTypeService_Delete(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/issueLinkType/100", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testRequestURL(t, r, "/rest/api/2/issueLinkType/100")
w.WriteHeader(http.StatusNoContent)
})
resp, err := testClient.IssueLinkType.Delete("100")
if resp.StatusCode != http.StatusNoContent {
t.Error("Expected issue not deleted.")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}