github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/dns/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 fake "github.com/gophercloud/gophercloud/openstack/networking/v2/common" 9 floatingiptest "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/testing" 10 networktest "github.com/gophercloud/gophercloud/openstack/networking/v2/networks/testing" 11 porttest "github.com/gophercloud/gophercloud/openstack/networking/v2/ports/testing" 12 th "github.com/gophercloud/gophercloud/testhelper" 13 ) 14 15 const NetworkCreateRequest = ` 16 { 17 "network": { 18 "name": "private", 19 "admin_state_up": true, 20 "dns_domain": "local." 21 } 22 }` 23 24 const NetworkCreateResponse = ` 25 { 26 "network": { 27 "status": "ACTIVE", 28 "subnets": ["08eae331-0402-425a-923c-34f7cfe39c1b"], 29 "name": "private", 30 "admin_state_up": true, 31 "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", 32 "created_at": "2019-06-30T04:15:37Z", 33 "updated_at": "2019-06-30T05:18:49Z", 34 "shared": false, 35 "id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324", 36 "provider:segmentation_id": 9876543210, 37 "provider:physical_network": null, 38 "provider:network_type": "local.", 39 "dns_domain": "local." 40 } 41 }` 42 43 const NetworkUpdateRequest = ` 44 { 45 "network": { 46 "name": "new_network_name", 47 "admin_state_up": false, 48 "dns_domain": "" 49 } 50 }` 51 52 const NetworkUpdateResponse = ` 53 { 54 "network": { 55 "status": "ACTIVE", 56 "subnets": ["08eae331-0402-425a-923c-34f7cfe39c1b"], 57 "name": "new_network_name", 58 "admin_state_up": false, 59 "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", 60 "created_at": "2019-06-30T04:15:37Z", 61 "updated_at": "2019-06-30T05:18:49Z", 62 "shared": false, 63 "id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324", 64 "provider:segmentation_id": 9876543210, 65 "provider:physical_network": null, 66 "provider:network_type": "local.", 67 "dns_domain": "" 68 } 69 }` 70 71 func PortHandleListSuccessfully(t *testing.T) { 72 th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { 73 th.TestMethod(t, r, "GET") 74 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 75 76 th.AssertEquals(t, r.RequestURI, "/v2.0/ports?dns_name=test-port") 77 78 w.Header().Add("Content-Type", "application/json") 79 w.WriteHeader(http.StatusOK) 80 81 fmt.Fprintf(w, porttest.ListResponse) 82 }) 83 } 84 85 func PortHandleGet(t *testing.T) { 86 th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", func(w http.ResponseWriter, r *http.Request) { 87 th.TestMethod(t, r, "GET") 88 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 89 90 w.Header().Add("Content-Type", "application/json") 91 w.WriteHeader(http.StatusOK) 92 93 fmt.Fprintf(w, porttest.GetResponse) 94 }) 95 } 96 97 func PortHandleCreate(t *testing.T) { 98 th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { 99 th.TestMethod(t, r, "POST") 100 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 101 th.TestHeader(t, r, "Content-Type", "application/json") 102 th.TestHeader(t, r, "Accept", "application/json") 103 th.TestJSONRequest(t, r, ` 104 { 105 "port": { 106 "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", 107 "name": "private-port", 108 "admin_state_up": true, 109 "fixed_ips": [ 110 { 111 "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", 112 "ip_address": "10.0.0.2" 113 } 114 ], 115 "security_groups": ["foo"], 116 "dns_name": "test-port" 117 } 118 } 119 `) 120 121 w.Header().Add("Content-Type", "application/json") 122 w.WriteHeader(http.StatusCreated) 123 124 fmt.Fprintf(w, ` 125 { 126 "port": { 127 "status": "DOWN", 128 "name": "private-port", 129 "allowed_address_pairs": [], 130 "admin_state_up": true, 131 "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", 132 "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", 133 "device_owner": "", 134 "mac_address": "fa:16:3e:c9:cb:f0", 135 "fixed_ips": [ 136 { 137 "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", 138 "ip_address": "10.0.0.2" 139 } 140 ], 141 "dns_name": "test-port", 142 "dns_assignment": [ 143 { 144 "hostname": "test-port", 145 "ip_address": "172.24.4.2", 146 "fqdn": "test-port.openstack.local." 147 } 148 ], 149 "id": "65c0ee9f-d634-4522-8954-51021b570b0d", 150 "security_groups": [ 151 "f0ac4394-7e4a-4409-9701-ba8be283dbc3" 152 ], 153 "device_id": "" 154 } 155 } 156 `) 157 }) 158 } 159 160 func PortHandleUpdate(t *testing.T) { 161 th.Mux.HandleFunc("/v2.0/ports/65c0ee9f-d634-4522-8954-51021b570b0d", func(w http.ResponseWriter, r *http.Request) { 162 th.TestMethod(t, r, "PUT") 163 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 164 th.TestHeader(t, r, "Content-Type", "application/json") 165 th.TestHeader(t, r, "Accept", "application/json") 166 th.TestJSONRequest(t, r, ` 167 { 168 "port": { 169 "name": "new_port_name", 170 "fixed_ips": [ 171 { 172 "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", 173 "ip_address": "10.0.0.3" 174 } 175 ], 176 "security_groups": [ 177 "f0ac4394-7e4a-4409-9701-ba8be283dbc3" 178 ], 179 "dns_name": "test-port1" 180 } 181 } 182 `) 183 184 w.Header().Add("Content-Type", "application/json") 185 w.WriteHeader(http.StatusOK) 186 187 fmt.Fprintf(w, ` 188 { 189 "port": { 190 "status": "DOWN", 191 "name": "new_port_name", 192 "admin_state_up": true, 193 "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", 194 "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", 195 "device_owner": "", 196 "mac_address": "fa:16:3e:c9:cb:f0", 197 "fixed_ips": [ 198 { 199 "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", 200 "ip_address": "10.0.0.3" 201 } 202 ], 203 "id": "65c0ee9f-d634-4522-8954-51021b570b0d", 204 "security_groups": [ 205 "f0ac4394-7e4a-4409-9701-ba8be283dbc3" 206 ], 207 "device_id": "", 208 "dns_name": "test-port1", 209 "dns_assignment": [ 210 { 211 "hostname": "test-port1", 212 "ip_address": "172.24.4.2", 213 "fqdn": "test-port1.openstack.local." 214 } 215 ] 216 } 217 } 218 `) 219 }) 220 } 221 222 func FloatingIPHandleList(t *testing.T) { 223 th.Mux.HandleFunc("/v2.0/floatingips", func(w http.ResponseWriter, r *http.Request) { 224 th.TestMethod(t, r, "GET") 225 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 226 227 th.AssertEquals(t, r.RequestURI, "/v2.0/floatingips?dns_domain=local.&dns_name=test-fip") 228 229 w.Header().Add("Content-Type", "application/json") 230 w.WriteHeader(http.StatusOK) 231 232 fmt.Fprintf(w, floatingiptest.ListResponseDNS) 233 }) 234 } 235 236 func FloatingIPHandleGet(t *testing.T) { 237 th.Mux.HandleFunc("/v2.0/floatingips/2f95fd2b-9f6a-4e8e-9e9a-2cbe286cbf9e", func(w http.ResponseWriter, r *http.Request) { 238 th.TestMethod(t, r, "GET") 239 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 240 241 w.Header().Add("Content-Type", "application/json") 242 w.WriteHeader(http.StatusOK) 243 244 fmt.Fprintf(w, fmt.Sprintf(`{"floatingip": %s}`, floatingiptest.FipDNS)) 245 }) 246 } 247 248 func FloatingIPHandleCreate(t *testing.T) { 249 th.Mux.HandleFunc("/v2.0/floatingips", func(w http.ResponseWriter, r *http.Request) { 250 th.TestMethod(t, r, "POST") 251 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 252 th.TestHeader(t, r, "Content-Type", "application/json") 253 th.TestHeader(t, r, "Accept", "application/json") 254 th.TestJSONRequest(t, r, ` 255 { 256 "floatingip": { 257 "floating_network_id": "6d67c30a-ddb4-49a1-bec3-a65b286b4170", 258 "dns_name": "test-fip", 259 "dns_domain": "local." 260 } 261 } 262 `) 263 264 w.Header().Add("Content-Type", "application/json") 265 w.WriteHeader(http.StatusCreated) 266 267 fmt.Fprintf(w, fmt.Sprintf(`{"floatingip": %s}`, floatingiptest.FipDNS)) 268 }) 269 } 270 271 func NetworkHandleList(t *testing.T) { 272 th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { 273 th.TestMethod(t, r, "GET") 274 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 275 276 th.AssertEquals(t, r.RequestURI, "/v2.0/networks?dns_domain=local.") 277 278 w.Header().Add("Content-Type", "application/json") 279 w.WriteHeader(http.StatusOK) 280 281 fmt.Fprintf(w, networktest.ListResponse) 282 }) 283 } 284 285 func NetworkHandleGet(t *testing.T) { 286 th.Mux.HandleFunc("/v2.0/networks/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) { 287 th.TestMethod(t, r, "GET") 288 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 289 290 w.Header().Add("Content-Type", "application/json") 291 w.WriteHeader(http.StatusOK) 292 293 fmt.Fprintf(w, networktest.GetResponse) 294 }) 295 } 296 297 func NetworkHandleCreate(t *testing.T) { 298 th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { 299 th.TestMethod(t, r, "POST") 300 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 301 th.TestHeader(t, r, "Content-Type", "application/json") 302 th.TestHeader(t, r, "Accept", "application/json") 303 th.TestJSONRequest(t, r, NetworkCreateRequest) 304 w.Header().Add("Content-Type", "application/json") 305 w.WriteHeader(http.StatusCreated) 306 307 fmt.Fprintf(w, NetworkCreateResponse) 308 }) 309 } 310 311 func NetworkHandleUpdate(t *testing.T) { 312 th.Mux.HandleFunc("/v2.0/networks/db193ab3-96e3-4cb3-8fc5-05f4296d0324", func(w http.ResponseWriter, r *http.Request) { 313 th.TestMethod(t, r, "PUT") 314 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 315 th.TestHeader(t, r, "Content-Type", "application/json") 316 th.TestHeader(t, r, "Accept", "application/json") 317 th.TestJSONRequest(t, r, NetworkUpdateRequest) 318 319 w.Header().Add("Content-Type", "application/json") 320 w.WriteHeader(http.StatusOK) 321 322 fmt.Fprintf(w, NetworkUpdateResponse) 323 }) 324 }