forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environments_test.go
120 lines (99 loc) · 3.9 KB
/
environments_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
package gitlab
import (
"fmt"
"log"
"net/http"
"reflect"
"testing"
)
func TestListEnvironments(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/environments", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testURL(t, r, "/api/v4/projects/1/environments?page=1&per_page=10")
fmt.Fprint(w, `[{"id": 1,"name": "review/fix-foo", "slug": "review-fix-foo-dfjre3", "external_url": "https://review-fix-foo-dfjre3.example.gitlab.com"}]`)
})
envs, _, err := client.Environments.ListEnvironments(1, &ListEnvironmentsOptions{Page: 1, PerPage: 10})
if err != nil {
log.Fatal(err)
}
want := []*Environment{{ID: 1, Name: "review/fix-foo", Slug: "review-fix-foo-dfjre3", ExternalURL: "https://review-fix-foo-dfjre3.example.gitlab.com"}}
if !reflect.DeepEqual(want, envs) {
t.Errorf("Environments.ListEnvironments returned %+v, want %+v", envs, want)
}
}
func TestGetEnvironment(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/environments/5949167", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"id":1,"name":"test/test"}`)
})
env, _, err := client.Environments.GetEnvironment(1, 5949167)
if err != nil {
t.Errorf("Environemtns.GetEnvironment returned error: %v", err)
}
want := &Environment{ID: 1, Name: "test/test"}
if !reflect.DeepEqual(want, env) {
t.Errorf("Environments.GetEnvironment returned %+v, want %+v", env, want)
}
}
func TestCreateEnvironment(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/environments", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testURL(t, r, "/api/v4/projects/1/environments")
fmt.Fprint(w, `{"id": 1,"name": "deploy", "slug": "deploy", "external_url": "https://deploy.example.gitlab.com"}`)
})
envs, _, err := client.Environments.CreateEnvironment(1, &CreateEnvironmentOptions{Name: String("deploy"), ExternalURL: String("https://deploy.example.gitlab.com")})
if err != nil {
log.Fatal(err)
}
want := &Environment{ID: 1, Name: "deploy", Slug: "deploy", ExternalURL: "https://deploy.example.gitlab.com"}
if !reflect.DeepEqual(want, envs) {
t.Errorf("Environments.CreateEnvironment returned %+v, want %+v", envs, want)
}
}
func TestEditEnvironment(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/environments/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testURL(t, r, "/api/v4/projects/1/environments/1")
fmt.Fprint(w, `{"id": 1,"name": "staging", "slug": "staging", "external_url": "https://staging.example.gitlab.com"}`)
})
envs, _, err := client.Environments.EditEnvironment(1, 1, &EditEnvironmentOptions{Name: String("staging"), ExternalURL: String("https://staging.example.gitlab.com")})
if err != nil {
log.Fatal(err)
}
want := &Environment{ID: 1, Name: "staging", Slug: "staging", ExternalURL: "https://staging.example.gitlab.com"}
if !reflect.DeepEqual(want, envs) {
t.Errorf("Environments.EditEnvironment returned %+v, want %+v", envs, want)
}
}
func TestDeleteEnvironment(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/environments/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testURL(t, r, "/api/v4/projects/1/environments/1")
})
_, err := client.Environments.DeleteEnvironment(1, 1)
if err != nil {
log.Fatal(err)
}
}
func TestStopEnvironment(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/environments/1/stop", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testURL(t, r, "/api/v4/projects/1/environments/1/stop")
})
_, err := client.Environments.StopEnvironment(1, 1)
if err != nil {
log.Fatal(err)
}
}