Skip to content

Commit b0111b2

Browse files
committed
remove unneeded instance code from fakeAPI
1 parent 8d70a47 commit b0111b2

File tree

1 file changed

+5
-97
lines changed

1 file changed

+5
-97
lines changed

cloud/linode/fake_linode_test.go

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ import (
1818
)
1919

2020
type fakeAPI struct {
21-
t *testing.T
22-
instance *linodego.Instance
23-
ips []*linodego.InstanceIP
24-
nb map[string]*linodego.NodeBalancer
25-
nbc map[string]*linodego.NodeBalancerConfig
26-
nbn map[string]*linodego.NodeBalancerNode
21+
t *testing.T
22+
nb map[string]*linodego.NodeBalancer
23+
nbc map[string]*linodego.NodeBalancerConfig
24+
nbn map[string]*linodego.NodeBalancerNode
2725

2826
requests map[fakeRequest]struct{}
2927
}
@@ -40,42 +38,8 @@ type filterStruct struct {
4038
}
4139

4240
func newFake(t *testing.T) *fakeAPI {
43-
publicIP := net.ParseIP("45.79.101.25")
44-
privateIP := net.ParseIP("192.168.133.65")
45-
instanceName := "test-instance"
46-
region := "us-east"
4741
return &fakeAPI{
48-
t: t,
49-
instance: &linodego.Instance{
50-
Label: instanceName,
51-
Region: region,
52-
Image: "linode/ubuntu16.04lts",
53-
Type: "g6-standard-2",
54-
Group: "Linode-Group",
55-
ID: 123,
56-
Status: "running",
57-
Hypervisor: "kvm",
58-
IPv4: []*net.IP{
59-
&publicIP,
60-
&privateIP,
61-
},
62-
},
63-
ips: []*linodego.InstanceIP{
64-
{
65-
Address: publicIP.String(),
66-
Public: true,
67-
LinodeID: 123,
68-
Type: "ipv4",
69-
Region: region,
70-
},
71-
{
72-
Address: privateIP.String(),
73-
Public: false,
74-
LinodeID: 123,
75-
Type: "ipv4",
76-
Region: region,
77-
},
78-
},
42+
t: t,
7943
nb: make(map[string]*linodego.NodeBalancer),
8044
nbc: make(map[string]*linodego.NodeBalancerConfig),
8145
nbn: make(map[string]*linodego.NodeBalancerNode),
@@ -112,62 +76,6 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
11276
case "GET":
11377
whichAPI := strings.Split(urlPath[1:], "/")
11478
switch whichAPI[0] {
115-
case "linode":
116-
switch whichAPI[1] {
117-
case "instances":
118-
rx, _ := regexp.Compile("/linode/instances/[0-9]+/ips")
119-
if rx.MatchString(urlPath) {
120-
resp := linodego.InstanceIPAddressResponse{
121-
IPv4: &linodego.InstanceIPv4Response{
122-
Public: []*linodego.InstanceIP{f.ips[0]},
123-
Private: []*linodego.InstanceIP{f.ips[1]},
124-
},
125-
}
126-
rr, _ := json.Marshal(resp)
127-
_, _ = w.Write(rr)
128-
return
129-
}
130-
131-
rx, _ = regexp.Compile("/linode/instances/[0-9]+")
132-
if rx.MatchString(urlPath) {
133-
id := filepath.Base(urlPath)
134-
if id == strconv.Itoa(f.instance.ID) {
135-
rr, _ := json.Marshal(&f.instance)
136-
_, _ = w.Write(rr)
137-
}
138-
return
139-
}
140-
141-
rx, _ = regexp.Compile("/linode/instances")
142-
if rx.MatchString(urlPath) {
143-
res := 0
144-
data := []linodego.Instance{}
145-
filter := r.Header.Get("X-Filter")
146-
if filter == "" {
147-
data = append(data, *f.instance)
148-
} else {
149-
var fs filterStruct
150-
err := json.Unmarshal([]byte(filter), &fs)
151-
if err != nil {
152-
f.t.Fatal(err)
153-
}
154-
if fs.Label == f.instance.Label {
155-
data = append(data, *f.instance)
156-
}
157-
}
158-
resp := linodego.InstancesPagedResponse{
159-
PageOptions: &linodego.PageOptions{
160-
Page: 1,
161-
Pages: 1,
162-
Results: res,
163-
},
164-
Data: data,
165-
}
166-
rr, _ := json.Marshal(resp)
167-
_, _ = w.Write(rr)
168-
return
169-
}
170-
}
17179
case "nodebalancers":
17280
rx, _ := regexp.Compile("/nodebalancers/[0-9]+/configs/[0-9]+/nodes/[0-9]+")
17381
if rx.MatchString(urlPath) {

0 commit comments

Comments
 (0)