forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreleaselinks_test.go
143 lines (125 loc) · 3.59 KB
/
releaselinks_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
package gitlab
import (
"fmt"
"net/http"
"testing"
)
const exampleReleaseLinkList = `[
{
"id": 2,
"name": "awesome-v0.2.msi",
"url": "http://192.168.10.15:3000/msi",
"external": true
},
{
"id": 1,
"name": "awesome-v0.2.dmg",
"url": "http://192.168.10.15:3000",
"external": true
}
]`
func TestReleaseLinksService_ListReleaseLinks(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/releases/v0.1/assets/links",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, exampleReleaseLinkList)
})
releaseLinks, _, err := client.ReleaseLinks.ListReleaseLinks(
1, "v0.1", &ListReleaseLinksOptions{},
)
if err != nil {
t.Error(err)
}
if len(releaseLinks) != 2 {
t.Error("expected 2 links")
}
if releaseLinks[0].Name != "awesome-v0.2.msi" {
t.Errorf("release link name, expected '%s', got '%s'", "awesome-v0.2.msi",
releaseLinks[0].Name)
}
}
const exampleReleaseLink = `{
"id":1,
"name":"awesome-v0.2.dmg",
"url":"http://192.168.10.15:3000",
"external":true
}`
func TestReleaseLinksService_CreateReleaseLink(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/releases/v0.1/assets/links",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, exampleReleaseLink)
})
releaseLink, _, err := client.ReleaseLinks.CreateReleaseLink(
1, "v0.1",
&CreateReleaseLinkOptions{
Name: String("awesome-v0.2.dmg"),
URL: String("http://192.168.10.15:3000"),
})
if err != nil {
t.Error(err)
}
if releaseLink.Name != "awesome-v0.2.dmg" {
t.Errorf("release link name, expected '%s', got '%s'", "awesome-v0.2.dmg",
releaseLink.Name)
}
}
func TestReleaseLinksService_GetReleaseLink(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/releases/v0.1/assets/links/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, exampleReleaseLink)
})
releaseLink, _, err := client.ReleaseLinks.GetReleaseLink(1, "v0.1", 1)
if err != nil {
t.Error(err)
}
if releaseLink.Name != "awesome-v0.2.dmg" {
t.Errorf("release link name, expected '%s', got '%s'", "awesome-v0.2.dmg",
releaseLink.Name)
}
}
func TestReleaseLinksService_UpdateReleaseLink(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/releases/v0.1/assets/links/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
fmt.Fprint(w, exampleReleaseLink)
})
releaseLink, _, err := client.ReleaseLinks.UpdateReleaseLink(
1, "v0.1", 1,
&UpdateReleaseLinkOptions{
Name: String("awesome-v0.2.dmg"),
})
if err != nil {
t.Error(err)
}
if releaseLink.Name != "awesome-v0.2.dmg" {
t.Errorf("release link name, expected '%s', got '%s'", "awesome-v0.2.dmg",
releaseLink.Name)
}
}
func TestReleaseLinksService_DeleteReleaseLink(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/releases/v0.1/assets/links/1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
fmt.Fprint(w, exampleReleaseLink)
})
releaseLink, _, err := client.ReleaseLinks.DeleteReleaseLink(1, "v0.1", 1)
if err != nil {
t.Error(err)
}
if releaseLink.Name != "awesome-v0.2.dmg" {
t.Errorf("release link name, expected '%s', got '%s'", "awesome-v0.2.dmg",
releaseLink.Name)
}
}