-
Notifications
You must be signed in to change notification settings - Fork 56
/
startup_script_test.go
148 lines (118 loc) · 3.92 KB
/
startup_script_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
144
145
146
147
148
package govultr
import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestStartupScriptServiceHandler_Create(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/startup-scripts", func(writer http.ResponseWriter, request *http.Request) {
response := `{"startup_script": {"id": "14356","date_created": "2020-07-07 18:52:56","date_modified": "2020-07-07 18:59:54","name": "govultr","type": "boot","script": "dGVzdGFwaXVwZGF0ZQ=="}}`
fmt.Fprint(writer, response)
})
script := &StartupScriptReq{
Name: "govultr",
Type: "boot",
Script: "dGVzdGFwaXVwZGF0ZQ==",
}
s, _, err := client.StartupScript.Create(context.Background(), script)
if err != nil {
t.Errorf("StartupScript.Create returned %+v, expected %+v", err, nil)
}
expected := &StartupScript{
ID: "14356",
DateCreated: "2020-07-07 18:52:56",
DateModified: "2020-07-07 18:59:54",
Name: "govultr",
Type: "boot",
Script: "dGVzdGFwaXVwZGF0ZQ==",
}
if !reflect.DeepEqual(s, expected) {
t.Errorf("StartupScript.Create returned %+v, expected %+v", s, expected)
}
}
func TestStartupScriptServiceHandler_GET(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/startup-scripts/14350", func(writer http.ResponseWriter, request *http.Request) {
response := `{"startup_script": {"id": "14350","date_created": "2020-06-08 17:58:10","date_modified": "2020-06-08 17:59:54","name": "govultr","type": "pxe","script": "dGVzdA=="}}`
fmt.Fprint(writer, response)
})
scripts, _, err := client.StartupScript.Get(ctx, "14350")
if err != nil {
t.Errorf("StartupScript.Get returned error: %v", err)
}
expectedScript := &StartupScript{
ID: "14350",
DateCreated: "2020-06-08 17:58:10",
DateModified: "2020-06-08 17:59:54",
Name: "govultr",
Type: "pxe",
Script: "dGVzdA==",
}
if !reflect.DeepEqual(scripts, expectedScript) {
t.Errorf("StartupScript.Get scripts returned %+v, expected %+v", scripts, expectedScript)
}
}
func TestStartupScriptServiceHandler_Update(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/startup-scripts/1234", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})
script := &StartupScriptReq{
Name: "foo",
Type: "boot",
Script: "dGVzdA==",
}
err := client.StartupScript.Update(ctx, "1234", script)
if err != nil {
t.Errorf("StartupScript.Update returned error: %+v", err)
}
}
func TestStartupScriptServiceHandler_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/startup-scripts/1234", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})
err := client.StartupScript.Delete(ctx, "1234")
if err != nil {
t.Errorf("StartupScript.Delete returned %+v, expected %+v", err, nil)
}
}
func TestStartupScriptServiceHandler_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/startup-scripts", func(writer http.ResponseWriter, request *http.Request) {
response := `{"startup_scripts": [{"id": "14350","date_created": "2020-06-08 17:58:10","date_modified": "2020-06-08 17:59:54","name": "govultr","type": "pxe","script": "dGVzdA=="}],"meta": {"total": 1,"links": {"next": "","prev": ""}}}`
fmt.Fprint(writer, response)
})
scripts, meta, _, err := client.StartupScript.List(ctx, nil)
if err != nil {
t.Errorf("StartupScript.List returned error: %v", err)
}
expectedScript := []StartupScript{
{
ID: "14350",
DateCreated: "2020-06-08 17:58:10",
DateModified: "2020-06-08 17:59:54",
Name: "govultr",
Type: "pxe",
Script: "dGVzdA==",
},
}
expectedMeta := &Meta{
Total: 1,
Links: &Links{},
}
if !reflect.DeepEqual(scripts, expectedScript) {
t.Errorf("StartupScript.List scripts returned %+v, expected %+v", scripts, expectedScript)
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("StartupScript.List meta returned %+v, expected %+v", meta, expectedMeta)
}
}