func TestCreateWithOptionalFields(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/networks", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "network": { "name": "sample_network", "admin_state_up": true, "shared": true, "tenant_id": "12345" } } `) w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, `{}`) }) iTrue := true options := networks.CreateOpts{Name: "sample_network", AdminStateUp: &iTrue, Shared: &iTrue, TenantID: "12345"} _, err := networks.Create(fake.ServiceClient(), options).Extract() th.AssertNoErr(t, err) }
// authTokenPost verifies that providing certain AuthOptions and Scope results in an expected JSON structure. func authTokenPost(t *testing.T, options tokens.AuthOptions, scope *tokens.Scope, requestJSON string) { testhelper.SetupHTTP() defer testhelper.TeardownHTTP() client := gophercloud.ServiceClient{ ProviderClient: &gophercloud.ProviderClient{}, Endpoint: testhelper.Endpoint(), } testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { testhelper.TestMethod(t, r, "POST") testhelper.TestHeader(t, r, "Content-Type", "application/json") testhelper.TestHeader(t, r, "Accept", "application/json") testhelper.TestJSONRequest(t, r, requestJSON) w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, `{ "token": { "expires_at": "2014-10-02T13:45:00.000000Z" } }`) }) if scope != nil { options.Scope = *scope } _, err := tokens.Create(&client, &options).Extract() if err != nil { t.Errorf("Create returned an error: %v", err) } }
func TestGetRequest(t *testing.T) { testhelper.SetupHTTP() defer testhelper.TeardownHTTP() client := gophercloud.ServiceClient{ ProviderClient: &gophercloud.ProviderClient{ TokenID: "12345abcdef", }, Endpoint: testhelper.Endpoint(), } testhelper.Mux.HandleFunc("/auth/tokens", func(w http.ResponseWriter, r *http.Request) { testhelper.TestMethod(t, r, "GET") testhelper.TestHeader(t, r, "Content-Type", "") testhelper.TestHeader(t, r, "Accept", "application/json") testhelper.TestHeader(t, r, "X-Auth-Token", "12345abcdef") testhelper.TestHeader(t, r, "X-Subject-Token", "abcdef12345") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "token": { "expires_at": "2014-08-29T13:10:01.000000Z" } } `) }) token, err := tokens.Get(&client, "abcdef12345").Extract() if err != nil { t.Errorf("Info returned an error: %v", err) } expected, _ := time.Parse(time.UnixDate, "Fri Aug 29 13:10:01 UTC 2014") if token.ExpiresAt != gophercloud.JSONRFC3339Milli(expected) { t.Errorf("Expected expiration time %s, but was %s", expected.Format(time.UnixDate), time.Time(token.ExpiresAt).Format(time.UnixDate)) } }
// HandleListObjectsInfoSuccessfully creates an HTTP handler at `/testContainer` on the test handler mux that // responds with a `List` response when full info is requested. func HandleListObjectsInfoSuccessfully(t *testing.T) { th.Mux.HandleFunc("/testContainer", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.Header().Set("Content-Type", "application/json") r.ParseForm() marker := r.Form.Get("marker") switch marker { case "": fmt.Fprintf(w, `[ { "hash": "451e372e48e0f6b1114fa0724aa79fa1", "last_modified": "2016-08-17T22:11:58.602650", "bytes": 14, "name": "goodbye", "content_type": "application/octet-stream" }, { "hash": "451e372e48e0f6b1114fa0724aa79fa1", "last_modified": "2016-08-17T22:11:58.602650", "bytes": 14, "name": "hello", "content_type": "application/octet-stream" } ]`) case "hello": fmt.Fprintf(w, `[]`) default: t.Fatalf("Unexpected marker: [%s]", marker) } }) }
func MockTerminateConnectionResponse(t *testing.T) { th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "os-terminate_connection": { "connector": { "ip":"127.0.0.1", "host":"stack", "initiator":"iqn.1994-05.com.redhat:17cf566367d2", "multipath": true, "platform": "x86_64", "os_type": "linux2" } } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) fmt.Fprintf(w, `{}`) }) }
func MockCreateResponse(t *testing.T) { th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "volume": { "size": 75 } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "volume": { "size": 4, "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22" } } `) }) }
// HandleGetSuccessfully creates an HTTP handler at `/` on the test handler mux // that responds with a `Get` response. func HandleGetSuccessfully(t *testing.T) { th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "resources": { "rel/cdn": { "href-template": "services{?marker,limit}", "href-vars": { "marker": "param/marker", "limit": "param/limit" }, "hints": { "allow": [ "GET" ], "formats": { "application/json": {} } } } } } `) }) }
func MockCreateResponse(t *testing.T) { th.Mux.HandleFunc("/snapshots", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "snapshot": { "volume_id": "1234", "display_name": "snapshot-001" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "snapshot": { "volume_id": "1234", "display_name": "snapshot-001", "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", "display_description": "Daily backup", "volume_id": "1234", "status": "available", "size": 30, "created_at": "2012-02-29T03:50:07" } } `) }) }
func TestCreateAnyProtocol(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/fw/firewall_rules", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "firewall_rule": { "protocol": null, "description": "any to 192.168.1.0/24", "destination_ip_address": "192.168.1.0/24", "name": "any_to_192.168.1.0/24", "action": "allow", "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "firewall_rule":{ "protocol": null, "description": "any to 192.168.1.0/24", "source_port": null, "source_ip_address": null, "destination_ip_address": "192.168.1.0/24", "firewall_policy_id": "e2a5fb51-698c-4898-87e8-f1eee6b50919", "position": 2, "destination_port": null, "id": "f03bd950-6c56-4f5e-a307-45967078f507", "name": "any_to_192.168.1.0/24", "tenant_id": "80cf934d6ffb4ef5b244f1c512ad1e61", "enabled": true, "action": "allow", "ip_version": 4, "shared": false } } `) }) options := rules.CreateOpts{ TenantID: "80cf934d6ffb4ef5b244f1c512ad1e61", Protocol: rules.ProtocolAny, Description: "any to 192.168.1.0/24", DestinationIPAddress: "192.168.1.0/24", Name: "any_to_192.168.1.0/24", Action: "allow", } _, err := rules.Create(fake.ServiceClient(), options).Extract() th.AssertNoErr(t, err) }
func TestAssociateHealthMonitor(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/lb/pools/332abe93-f488-41ba-870b-2ac66be7f853/health_monitors", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "health_monitor":{ "id":"b624decf-d5d3-4c66-9a3d-f047e7786181" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, `{}`) }) _, err := pools.AssociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181").Extract() th.AssertNoErr(t, err) }
func TestCreate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/fw/firewall_policies", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "firewall_policy":{ "name": "policy", "firewall_rules": [ "98a58c87-76be-ae7c-a74e-b77fffb88d95", "11a58c87-76be-ae7c-a74e-b77fffb88a32" ], "description": "Firewall policy", "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", "audited": true, "shared": false } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "firewall_policy":{ "name": "policy", "firewall_rules": [ "98a58c87-76be-ae7c-a74e-b77fffb88d95", "11a58c87-76be-ae7c-a74e-b77fffb88a32" ], "tenant_id": "9145d91459d248b1b02fdaca97c6a75d", "audited": false, "id": "f2b08c1e-aa81-4668-8ae1-1401bcb0576c", "description": "Firewall policy" } } `) }) options := policies.CreateOpts{ TenantID: "9145d91459d248b1b02fdaca97c6a75d", Name: "policy", Description: "Firewall policy", Shared: gophercloud.Disabled, Audited: gophercloud.Enabled, Rules: []string{ "98a58c87-76be-ae7c-a74e-b77fffb88d95", "11a58c87-76be-ae7c-a74e-b77fffb88a32", }, } _, err := policies.Create(fake.ServiceClient(), options).Extract() th.AssertNoErr(t, err) }
func TestUpdate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/lb/health_monitors/b05e44b5-81f9-4551-b474-711a722698f7", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "PUT") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "health_monitor":{ "delay": 30, "timeout": 20, "max_retries": 10, "url_path": "/another_check", "expected_codes": "301", "admin_state_up": true } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) fmt.Fprintf(w, ` { "health_monitor": { "admin_state_up": true, "tenant_id": "4fd44f30292945e481c7b8a0c8908869", "delay": 30, "max_retries": 10, "http_method": "GET", "timeout": 20, "pools": [ { "status": "PENDING_CREATE", "status_description": null, "pool_id": "6e55751f-6ad4-4e53-b8d4-02e442cd21df" } ], "type": "PING", "id": "b05e44b5-81f9-4551-b474-711a722698f7" } } `) }) _, err := monitors.Update(fake.ServiceClient(), "b05e44b5-81f9-4551-b474-711a722698f7", monitors.UpdateOpts{ Delay: 30, Timeout: 20, MaxRetries: 10, URLPath: "/another_check", ExpectedCodes: "301", AdminStateUp: gophercloud.Enabled, }).Extract() th.AssertNoErr(t, err) }
func TestUpdate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/subnets/08eae331-0402-425a-923c-34f7cfe39c1b", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "PUT") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "subnet": { "name": "my_new_subnet", "dns_nameservers": ["foo"], "host_routes": [{"destination":"","nexthop": "bar"}] } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "subnet": { "name": "my_new_subnet", "enable_dhcp": true, "network_id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324", "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", "dns_nameservers": [], "allocation_pools": [ { "start": "10.0.0.2", "end": "10.0.0.254" } ], "host_routes": [], "ip_version": 4, "gateway_ip": "10.0.0.1", "cidr": "10.0.0.0/24", "id": "08eae331-0402-425a-923c-34f7cfe39c1b" } } `) }) opts := subnets.UpdateOpts{ Name: "my_new_subnet", DNSNameservers: []string{"foo"}, HostRoutes: []subnets.HostRoute{ {NextHop: "bar"}, }, } s, err := subnets.Update(fake.ServiceClient(), "08eae331-0402-425a-923c-34f7cfe39c1b", opts).Extract() th.AssertNoErr(t, err) th.AssertEquals(t, s.Name, "my_new_subnet") th.AssertEquals(t, s.ID, "08eae331-0402-425a-923c-34f7cfe39c1b") }
// HandleDeleteObjectSuccessfully creates an HTTP handler at `/testContainer/testObject` on the test handler mux that // responds with a `Delete` response. func HandleDeleteObjectSuccessfully(t *testing.T) { th.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "DELETE") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.WriteHeader(http.StatusNoContent) }) }
// HandleCopyObjectSuccessfully creates an HTTP handler at `/testContainer/testObject` on the test handler mux that // responds with a `Copy` response. func HandleCopyObjectSuccessfully(t *testing.T) { th.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "COPY") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") th.TestHeader(t, r, "Destination", "/newTestContainer/newTestObject") w.WriteHeader(http.StatusCreated) }) }
// HandleMemberGetSuccessfully sets up the test server to respond to a member Get request. func HandleMemberGetSuccessfully(t *testing.T) { th.Mux.HandleFunc("/v2.0/lbaas/pools/332abe93-f488-41ba-870b-2ac66be7f853/members/2a280670-c202-4b0b-a562-34077415aabf", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestHeader(t, r, "Accept", "application/json") fmt.Fprintf(w, SingleMemberBody) }) }
// HandleLoadbalancerGetStatusesTree sets up the test server to respond to a loadbalancer Get statuses tree request. func HandleLoadbalancerGetStatusesTree(t *testing.T) { th.Mux.HandleFunc("/v2.0/lbaas/loadbalancers/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/statuses", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestHeader(t, r, "Accept", "application/json") fmt.Fprintf(w, LoadbalancerStatuesesTree) }) }
// HandlePoolGetSuccessfully sets up the test server to respond to a pool Get request. func HandlePoolGetSuccessfully(t *testing.T) { th.Mux.HandleFunc("/v2.0/lbaas/pools/c3741b06-df4d-4715-b142-276b6bce75ab", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestHeader(t, r, "Accept", "application/json") fmt.Fprintf(w, SinglePoolBody) }) }
func TestCreate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/lb/health_monitors", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "health_monitor":{ "type":"HTTP", "tenant_id":"453105b9-1754-413f-aab1-55f1af620750", "delay":20, "timeout":10, "max_retries":5, "url_path":"/check", "expected_codes":"200-299" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "health_monitor":{ "id":"f3eeab00-8367-4524-b662-55e64d4cacb5", "tenant_id":"453105b9-1754-413f-aab1-55f1af620750", "type":"HTTP", "delay":20, "timeout":10, "max_retries":5, "http_method":"GET", "url_path":"/check", "expected_codes":"200-299", "admin_state_up":true, "status":"ACTIVE" } } `) }) _, err := monitors.Create(fake.ServiceClient(), monitors.CreateOpts{ Type: "HTTP", TenantID: "453105b9-1754-413f-aab1-55f1af620750", Delay: 20, Timeout: 10, MaxRetries: 5, URLPath: "/check", ExpectedCodes: "200-299", }).Extract() th.AssertNoErr(t, err) }
// HandlePasswordGetSuccessfully sets up the test server to respond to a password Get request. func HandlePasswordGetSuccessfully(t *testing.T) { th.Mux.HandleFunc("/servers/1234asdf/os-server-password", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestHeader(t, r, "Accept", "application/json") fmt.Fprintf(w, ServerPasswordBody) }) }
// HandleGetObjectSuccessfully creates an HTTP handler at `/testContainer/testObject` on the test handler mux that // responds with a `Get` response. func HandleGetObjectSuccessfully(t *testing.T) { th.Mux.HandleFunc("/testContainer/testObject", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "HEAD") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.Header().Add("X-Object-Meta-Gophercloud-Test", "objects") w.WriteHeader(http.StatusNoContent) }) }
// HandleHealthmonitorGetSuccessfully sets up the test server to respond to a healthmonitor Get request. func HandleHealthmonitorGetSuccessfully(t *testing.T) { th.Mux.HandleFunc("/v2.0/lbaas/healthmonitors/5d4b5228-33b0-4e60-b225-9b727c1a20e7", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestHeader(t, r, "Accept", "application/json") fmt.Fprintf(w, SingleHealthmonitorBody) }) }
// HandleCreateSuccessfully creates an HTTP handler at `/stacks` on the test handler mux // that responds with a `Create` response. func HandleCreateSuccessfully(t *testing.T, output string) { th.Mux.HandleFunc("/stacks", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, output) }) }
// HandleListenerGetSuccessfully sets up the test server to respond to a listener Get request. func HandleListenerGetSuccessfully(t *testing.T) { th.Mux.HandleFunc("/v2.0/lbaas/listeners/4ec89087-d057-4e2c-911f-60a3b47ee304", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestHeader(t, r, "Accept", "application/json") fmt.Fprintf(w, SingleListenerBody) }) }
func HandleCreate(t *testing.T) { th.Mux.HandleFunc("/v2.0/ports", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "port": { "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", "name": "private-port", "admin_state_up": true, "fixed_ips": [ { "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", "ip_address": "10.0.0.2" } ], "security_groups": ["foo"], "binding:host_id": "HOST1", "binding:vnic_type": "normal" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "port": { "status": "DOWN", "name": "private-port", "allowed_address_pairs": [], "admin_state_up": true, "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", "tenant_id": "d6700c0c9ffa4f1cb322cd4a1f3906fa", "device_owner": "", "mac_address": "fa:16:3e:c9:cb:f0", "fixed_ips": [ { "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", "ip_address": "10.0.0.2" } ], "binding:host_id": "HOST1", "binding:vnic_type": "normal", "id": "65c0ee9f-d634-4522-8954-51021b570b0d", "security_groups": [ "f0ac4394-7e4a-4409-9701-ba8be283dbc3" ], "device_id": "" } } `) }) }
func TestCreate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/security-group-rules", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "security_group_rule": { "direction": "ingress", "port_range_min": 80, "ethertype": "IPv4", "port_range_max": 80, "protocol": "tcp", "remote_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", "security_group_id": "a7734e61-b545-452d-a3cd-0189cbd9747a" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "security_group_rule": { "direction": "ingress", "ethertype": "IPv4", "id": "2bc0accf-312e-429a-956e-e4407625eb62", "port_range_max": 80, "port_range_min": 80, "protocol": "tcp", "remote_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", "remote_ip_prefix": null, "security_group_id": "a7734e61-b545-452d-a3cd-0189cbd9747a", "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" } } `) }) opts := rules.CreateOpts{ Direction: "ingress", PortRangeMin: 80, EtherType: rules.EtherType4, PortRangeMax: 80, Protocol: "tcp", RemoteGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5", SecGroupID: "a7734e61-b545-452d-a3cd-0189cbd9747a", } _, err := rules.Create(fake.ServiceClient(), opts).Extract() th.AssertNoErr(t, err) }
func MockInitializeConnectionResponse(t *testing.T) { th.Mux.HandleFunc("/volumes/cd281d77-8217-4830-be95-9528227c105c/action", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Content-Type", "application/json") th.TestHeader(t, r, "Accept", "application/json") th.TestJSONRequest(t, r, ` { "os-initialize_connection": { "connector": { "ip":"127.0.0.1", "host":"stack", "initiator":"iqn.1994-05.com.redhat:17cf566367d2", "multipath": false, "platform": "x86_64", "os_type": "linux2" } } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) fmt.Fprintf(w, `{ "connection_info": { "data": { "target_portals": [ "172.31.17.48:3260" ], "auth_method": "CHAP", "auth_username": "******", "access_mode": "rw", "target_lun": 0, "volume_id": "cd281d77-8217-4830-be95-9528227c105c", "target_luns": [ 0 ], "target_iqns": [ "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c" ], "auth_password": "******", "target_discovered": false, "encrypted": false, "qos_specs": null, "target_iqn": "iqn.2010-10.org.openstack:volume-cd281d77-8217-4830-be95-9528227c105c", "target_portal": "172.31.17.48:3260" }, "driver_volume_type": "iscsi" } }`) }) }
// HandleMetadataGetSuccessfully sets up the test server to respond to a metadata Get request. func HandleMetadataGetSuccessfully(t *testing.T) { th.Mux.HandleFunc("/servers/1234asdf/metadata", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.WriteHeader(http.StatusOK) w.Write([]byte(`{ "metadata": {"foo":"bar", "this":"that"}}`)) }) }
// HandleTokenGet expects a Get against a /tokens handler, ensures that the request body has been // constructed properly given certain auth options, and returns the result. func HandleTokenGet(t *testing.T, token string) { th.Mux.HandleFunc("/tokens/"+token, func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "Accept", "application/json") th.TestHeader(t, r, "X-Auth-Token", thclient.TokenID) w.WriteHeader(http.StatusOK) fmt.Fprintf(w, TokenGetResponse) }) }
// HandleDeleteSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87` // on the test handler mux that responds with a `Delete` response. func HandleDeleteSuccessfully(t *testing.T) { th.Mux.HandleFunc("/stacks/gophercloud-test-stack-2/db6977b2-27aa-4775-9ae7-6213212d4ada", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "DELETE") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) th.TestHeader(t, r, "Accept", "application/json") w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusNoContent) }) }