forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_variables_test.go
119 lines (98 loc) · 3.2 KB
/
build_variables_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
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
const (
myKey = "MY_KEY"
myValue = "MY_VALUE"
myKey2 = "MY_KEY2"
myValue2 = "MY_VALUE2"
myNewValue = "MY_NEW_VALUE"
)
func TestListBuildVariables(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/variables", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprintf(w,
`[{"key":"%s","value":"%s"},{"key":"%s","value":"%s"}]`, myKey, myValue, myKey2, myValue2)
})
variables, _, err := client.BuildVariables.ListBuildVariables(1, nil)
if err != nil {
t.Errorf("ListBuildVariables returned error: %v", err)
}
want := []*BuildVariable{{Key: myKey, Value: myValue}, {Key: myKey2, Value: myValue2}}
if !reflect.DeepEqual(want, variables) {
t.Errorf("ListBuildVariables returned %+v, want %+v", variables, want)
}
}
func TestGetBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/variables/"+myKey, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprintf(w, `{"key":"%s","value":"%s"}`, myKey, myValue)
})
variable, _, err := client.BuildVariables.GetBuildVariable(1, myKey)
if err != nil {
t.Errorf("GetBuildVariable returned error: %v", err)
}
want := &BuildVariable{Key: myKey, Value: myValue}
if !reflect.DeepEqual(want, variable) {
t.Errorf("GetBuildVariable returned %+v, want %+v", variable, want)
}
}
func TestCreateBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/variables", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testJSONBody(t, r, values{
"key": myKey,
"value": myValue,
})
fmt.Fprintf(w, `{"key":"%s","value":"%s"}`, myKey, myValue)
})
variable, _, err := client.BuildVariables.CreateBuildVariable(1, myKey, myValue)
if err != nil {
t.Errorf("CreateBuildVariable returned error: %v", err)
}
want := &BuildVariable{Key: myKey, Value: myValue}
if !reflect.DeepEqual(want, variable) {
t.Errorf("CreateBuildVariable returned %+v, want %+v", variable, want)
}
}
func TestUpdateBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/variables/"+myKey, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, values{
"key": myKey,
"value": myNewValue,
})
fmt.Fprintf(w, `{"key":"%s","value":"%s"}`, myKey, myNewValue)
})
variable, _, err := client.BuildVariables.UpdateBuildVariable(1, myKey, myNewValue)
if err != nil {
t.Errorf("UpdateBuildVariable returned error: %v", err)
}
want := &BuildVariable{Key: myKey, Value: myNewValue}
if !reflect.DeepEqual(want, variable) {
t.Errorf("UpdateBuildVariable returned %+v, want %+v", variable, want)
}
}
func TestRemoveBuildVariable(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/1/variables/"+myKey, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
_, err := client.BuildVariables.RemoveBuildVariable(1, myKey)
if err != nil {
t.Errorf("RemoveBuildVariable returned error: %v", err)
}
}