forked from gophercloud/gophercloud
/
fixtures.go
162 lines (149 loc) · 4.87 KB
/
fixtures.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/yyf330/gophercloud/openstack/compute/v2/extensions/attachinterfaces"
th "github.com/yyf330/gophercloud/testhelper"
"github.com/yyf330/gophercloud/testhelper/client"
)
// ListInterfacesExpected represents an expected repsonse from a ListInterfaces request.
var ListInterfacesExpected = []attachinterfaces.Interface{
{
PortState: "ACTIVE",
FixedIPs: []attachinterfaces.FixedIP{
{
SubnetID: "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
IPAddress: "10.0.0.7",
},
{
SubnetID: "45906d64-a548-4276-h1f8-kcffa80fjbnl",
IPAddress: "10.0.0.8",
},
},
PortID: "0dde1598-b374-474e-986f-5b8dd1df1d4e",
NetID: "8a5fe506-7e9f-4091-899b-96336909d93c",
MACAddr: "fa:16:3e:38:2d:80",
},
}
// GetInterfaceExpected represents an expected repsonse from a GetInterface request.
var GetInterfaceExpected = attachinterfaces.Interface{
PortState: "ACTIVE",
FixedIPs: []attachinterfaces.FixedIP{
{
SubnetID: "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
IPAddress: "10.0.0.7",
},
{
SubnetID: "45906d64-a548-4276-h1f8-kcffa80fjbnl",
IPAddress: "10.0.0.8",
},
},
PortID: "0dde1598-b374-474e-986f-5b8dd1df1d4e",
NetID: "8a5fe506-7e9f-4091-899b-96336909d93c",
MACAddr: "fa:16:3e:38:2d:80",
}
// CreateInterfacesExpected represents an expected repsonse from a CreateInterface request.
var CreateInterfacesExpected = attachinterfaces.Interface{
PortState: "ACTIVE",
FixedIPs: []attachinterfaces.FixedIP{
{
SubnetID: "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
IPAddress: "10.0.0.7",
},
},
PortID: "0dde1598-b374-474e-986f-5b8dd1df1d4e",
NetID: "8a5fe506-7e9f-4091-899b-96336909d93c",
MACAddr: "fa:16:3e:38:2d:80",
}
// HandleInterfaceListSuccessfully sets up the test server to respond to a ListInterfaces request.
func HandleInterfaceListSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{
"interfaceAttachments": [
{
"port_state":"ACTIVE",
"fixed_ips": [
{
"subnet_id": "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
"ip_address": "10.0.0.7"
},
{
"subnet_id": "45906d64-a548-4276-h1f8-kcffa80fjbnl",
"ip_address": "10.0.0.8"
}
],
"port_id": "0dde1598-b374-474e-986f-5b8dd1df1d4e",
"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c",
"mac_addr": "fa:16:3e:38:2d:80"
}
]
}`)
})
}
// HandleInterfaceGetSuccessfully sets up the test server to respond to a GetInterface request.
func HandleInterfaceGetSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface/0dde1598-b374-474e-986f-5b8dd1df1d4e", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{
"interfaceAttachment":
{
"port_state":"ACTIVE",
"fixed_ips": [
{
"subnet_id": "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
"ip_address": "10.0.0.7"
},
{
"subnet_id": "45906d64-a548-4276-h1f8-kcffa80fjbnl",
"ip_address": "10.0.0.8"
}
],
"port_id": "0dde1598-b374-474e-986f-5b8dd1df1d4e",
"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c",
"mac_addr": "fa:16:3e:38:2d:80"
}
}`)
})
}
// HandleInterfaceCreateSuccessfully sets up the test server to respond to a CreateInterface request.
func HandleInterfaceCreateSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, `{
"interfaceAttachment": {
"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c"
}
}`)
w.Header().Add("Content-Type", "application/json")
fmt.Fprintf(w, `{
"interfaceAttachment":
{
"port_state":"ACTIVE",
"fixed_ips": [
{
"subnet_id": "d7906db4-a566-4546-b1f4-5c7fa70f0bf3",
"ip_address": "10.0.0.7"
}
],
"port_id": "0dde1598-b374-474e-986f-5b8dd1df1d4e",
"net_id": "8a5fe506-7e9f-4091-899b-96336909d93c",
"mac_addr": "fa:16:3e:38:2d:80"
}
}`)
})
}
// HandleInterfaceDeleteSuccessfully sets up the test server to respond to a DeleteInterface request.
func HandleInterfaceDeleteSuccessfully(t *testing.T) {
th.Mux.HandleFunc("/servers/b07e7a3b-d951-4efc-a4f9-ac9f001afb7f/os-interface/0dde1598-b374-474e-986f-5b8dd1df1d4e", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusAccepted)
})
}