forked from andygrunwald/go-jira
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version_test.go
112 lines (101 loc) · 2.64 KB
/
version_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
package jira
import (
"fmt"
"net/http"
"testing"
)
func TestVersionService_Get_Success(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/version/10002", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testRequestURL(t, r, "/rest/api/2/version/10002")
fmt.Fprint(w, `{
"self": "http://www.example.com/jira/rest/api/2/version/10002",
"id": "10002",
"description": "An excellent version",
"name": "New Version 1",
"archived": false,
"released": true,
"releaseDate": "2010-07-06",
"overdue": true,
"userReleaseDate": "6/Jul/2010",
"startDate" : "2010-07-01",
"projectId": 10000
}`)
})
version, _, err := testClient.Version.Get(10002)
if version == nil {
t.Error("Expected version. Issue is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestVersionService_Create(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/version", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testRequestURL(t, r, "/rest/api/2/version")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{
"description": "An excellent version",
"name": "New Version 1",
"archived": false,
"released": true,
"releaseDate": "2010-07-06",
"userReleaseDate": "6/Jul/2010",
"project": "PXA",
"projectId": 10000
}`)
})
v := &Version{
Name: "New Version 1",
Description: "An excellent version",
ProjectID: 10000,
Released: Bool(true),
Archived: Bool(false),
ReleaseDate: "2010-07-06",
UserReleaseDate: "6/Jul/2010",
StartDate: "2018-07-01",
}
version, _, err := testClient.Version.Create(v)
if version == nil {
t.Error("Expected version. Version is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}
func TestServiceService_Update(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/rest/api/2/version/10002", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testRequestURL(t, r, "/rest/api/2/version/10002")
fmt.Fprint(w, `{
"description": "An excellent updated version",
"name": "New Updated Version 1",
"archived": false,
"released": true,
"releaseDate": "2010-07-06",
"userReleaseDate": "6/Jul/2010",
"startDate" : "2010-07-01",
"project": "PXA",
"projectId": 10000
}`)
})
v := &Version{
ID: "10002",
Name: "New Updated Version 1",
Description: "An excellent updated version",
}
version, _, err := testClient.Version.Update(v)
if version == nil {
t.Error("Expected version. Version is nil")
}
if err != nil {
t.Errorf("Error given: %s", err)
}
}