func TestURLs(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.AssertEquals(t, th.Endpoint()+"v2.0/lbaas/loadbalancers", rootURL(fake.ServiceClient())) th.AssertEquals(t, th.Endpoint()+"v2.0/lbaas/loadbalancers/foo", resourceURL(fake.ServiceClient(), "foo")) }
func TestURLs(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.AssertEquals(t, th.Endpoint()+"v2.0/security-groups", rootURL(fake.ServiceClient())) th.AssertEquals(t, th.Endpoint()+"v2.0/security-groups/foo", resourceURL(fake.ServiceClient(), "foo")) }
func TestAddInterfaceRequiredOpts(t *testing.T) { _, err := AddInterface(fake.ServiceClient(), "foo", InterfaceOpts{}).Extract() if err == nil { t.Fatalf("Expected error, got none") } _, err = AddInterface(fake.ServiceClient(), "foo", InterfaceOpts{SubnetID: "bar", PortID: "baz"}).Extract() if err == nil { t.Fatalf("Expected error, got none") } }
func TestRequiredCreateOpts(t *testing.T) { res := Create(fake.ServiceClient(), CreateOpts{}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{Type: TypeHTTP}) if res.Err == nil { t.Fatalf("Expected error, got none") } }
func TestRequiredFieldsForCreate(t *testing.T) { res1 := Create(fake.ServiceClient(), CreateOpts{FloatingNetworkID: ""}) if res1.Err == nil { t.Fatalf("Expected error, got none") } res2 := Create(fake.ServiceClient(), CreateOpts{FloatingNetworkID: "foo", PortID: ""}) if res2.Err == nil { t.Fatalf("Expected error, got none") } }
func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/extensions/agent", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "extension": { "updated": "2013-02-03T10:00:00-00:00", "name": "agent", "links": [], "namespace": "http://docs.openstack.org/ext/agent/api/v2.0", "alias": "agent", "description": "The agent management extension." } } `) }) ext, err := Get(fake.ServiceClient(), "agent").Extract() th.AssertNoErr(t, err) th.AssertEquals(t, ext.Updated, "2013-02-03T10:00:00-00:00") th.AssertEquals(t, ext.Name, "agent") th.AssertEquals(t, ext.Namespace, "http://docs.openstack.org/ext/agent/api/v2.0") th.AssertEquals(t, ext.Alias, "agent") th.AssertEquals(t, ext.Description, "The agent management extension.") }
func TestListMembers(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleMemberListSuccessfully(t) pages := 0 err := ListAssociateMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", MemberListOpts{}).EachPage(func(page pagination.Page) (bool, error) { pages++ actual, err := ExtractMembers(page) if err != nil { return false, err } if len(actual) != 2 { t.Fatalf("Expected 2 members, got %d", len(actual)) } th.CheckDeepEquals(t, MemberWeb, actual[0]) th.CheckDeepEquals(t, MemberDb, actual[1]) return true, nil }) th.AssertNoErr(t, err) if pages != 1 { t.Errorf("Expected 1 page, saw %d", pages) } }
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 := CreateOpts{Name: "sample_network", AdminStateUp: &iTrue, Shared: &iTrue, TenantID: "12345"} _, err := Create(fake.ServiceClient(), options).Extract() th.AssertNoErr(t, err) }
func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleGet(t) n, err := Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").Extract() th.AssertNoErr(t, err) th.AssertEquals(t, n.Status, "ACTIVE") th.AssertEquals(t, n.Name, "") th.AssertEquals(t, n.AdminStateUp, true) th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") th.AssertEquals(t, n.TenantID, "7e02058126cc4950b75f9970368ba177") th.AssertEquals(t, n.DeviceOwner, "network:router_interface") th.AssertEquals(t, n.MACAddress, "fa:16:3e:23:fd:d7") th.AssertDeepEquals(t, n.FixedIPs, []ports.IP{ {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"}, }) th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2") th.AssertDeepEquals(t, n.SecurityGroups, []string{}) th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e") th.AssertEquals(t, n.HostID, "devstack") th.AssertEquals(t, n.VNICType, "normal") th.AssertEquals(t, n.VIFType, "ovs") th.AssertDeepEquals(t, n.VIFDetails, map[string]interface{}{"port_filter": true, "ovs_hybrid_plug": true}) }
func TestListHealthmonitors(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleHealthmonitorListSuccessfully(t) pages := 0 err := List(fake.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { pages++ actual, err := ExtractMonitors(page) if err != nil { return false, err } if len(actual) != 2 { t.Fatalf("Expected 2 healthmonitors, got %d", len(actual)) } th.CheckDeepEquals(t, HealthmonitorWeb, actual[0]) th.CheckDeepEquals(t, HealthmonitorDb, actual[1]) return true, nil }) th.AssertNoErr(t, err) if pages != 1 { t.Errorf("Expected 1 page, saw %d", pages) } }
func TestRequiredCreateOpts(t *testing.T) { res := Create(fake.ServiceClient(), CreateOpts{}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo"}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{NetworkID: "foo", CIDR: "bar", IPVersion: 40}) if res.Err == nil { t.Fatalf("Expected error, got none") } }
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 := CreateOpts{ TenantID: "9145d91459d248b1b02fdaca97c6a75d", Name: "policy", Description: "Firewall policy", Shared: No, Audited: Yes, Rules: []string{ "98a58c87-76be-ae7c-a74e-b77fffb88d95", "11a58c87-76be-ae7c-a74e-b77fffb88a32", }, } _, err := 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 := AssociateMonitor(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "b624decf-d5d3-4c66-9a3d-f047e7786181").Extract() th.AssertNoErr(t, err) }
func TestUpdate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleUpdate(t) options := UpdateOpts{ UpdateOptsBuilder: ports.UpdateOpts{ Name: "new_port_name", FixedIPs: []ports.IP{ {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, }, SecurityGroups: []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}, }, HostID: "HOST1", VNICType: "normal", } s, err := Update(fake.ServiceClient(), "65c0ee9f-d634-4522-8954-51021b570b0d", options).Extract() th.AssertNoErr(t, err) th.AssertEquals(t, s.Name, "new_port_name") th.AssertDeepEquals(t, s.FixedIPs, []ports.IP{ {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.3"}, }) th.AssertDeepEquals(t, s.SecurityGroups, []string{"f0ac4394-7e4a-4409-9701-ba8be283dbc3"}) th.AssertEquals(t, s.HostID, "HOST1") th.AssertEquals(t, s.VNICType, "normal") }
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 := UpdateOpts{ Name: "my_new_subnet", DNSNameservers: []string{"foo"}, HostRoutes: []HostRoute{ HostRoute{NextHop: "bar"}, }, } s, err := 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") }
func TestDeleteLoadbalancer(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleLoadbalancerDeletionSuccessfully(t) res := Delete(fake.ServiceClient(), "36e08a3e-a78f-4b40-a229-1e7e23eee1ab") th.AssertNoErr(t, res.Err) }
func TestDeleteMember(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleMemberDeletionSuccessfully(t) res := DeleteMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", "2a280670-c202-4b0b-a562-34077415aabf") th.AssertNoErr(t, res.Err) }
func TestDeletePool(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandlePoolDeletionSuccessfully(t) res := Delete(fake.ServiceClient(), "c3741b06-df4d-4715-b142-276b6bce75ab") th.AssertNoErr(t, res.Err) }
func TestDeleteHealthmonitor(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleHealthmonitorDeletionSuccessfully(t) res := Delete(fake.ServiceClient(), "5d4b5228-33b0-4e60-b225-9b727c1a20e7") th.AssertNoErr(t, res.Err) }
func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/security-groups/85cc3048-abc3-43cc-89b3-377341426ac5", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "security_group": { "description": "default", "id": "85cc3048-abc3-43cc-89b3-377341426ac5", "name": "default", "security_group_rules": [ { "direction": "egress", "ethertype": "IPv6", "id": "3c0e45ff-adaf-4124-b083-bf390e5482ff", "port_range_max": null, "port_range_min": null, "protocol": null, "remote_group_id": null, "remote_ip_prefix": null, "security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" }, { "direction": "egress", "ethertype": "IPv4", "id": "93aa42e5-80db-4581-9391-3a608bd0e448", "port_range_max": null, "port_range_min": null, "protocol": null, "remote_group_id": null, "remote_ip_prefix": null, "security_group_id": "85cc3048-abc3-43cc-89b3-377341426ac5", "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" } ], "tenant_id": "e4f50856753b4dc6afee5fa6b9b6c550" } } `) }) sg, err := Get(fake.ServiceClient(), "85cc3048-abc3-43cc-89b3-377341426ac5").Extract() th.AssertNoErr(t, err) th.AssertEquals(t, "default", sg.Description) th.AssertEquals(t, "85cc3048-abc3-43cc-89b3-377341426ac5", sg.ID) th.AssertEquals(t, "default", sg.Name) th.AssertEquals(t, 2, len(sg.Rules)) th.AssertEquals(t, "e4f50856753b4dc6afee5fa6b9b6c550", sg.TenantID) }
func TestRequiredMemberCreateOpts(t *testing.T) { res := CreateAssociateMember(fake.ServiceClient(), "", MemberCreateOpts{}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = CreateAssociateMember(fake.ServiceClient(), "", MemberCreateOpts{Address: "1.2.3.4", ProtocolPort: 80}) if res.Err == nil || res.Err != errPoolIdRequired { t.Fatalf("Expected '%s' error, but got '%s'", errPoolIdRequired, res.Err) } res = CreateAssociateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", MemberCreateOpts{ProtocolPort: 80}) if res.Err == nil || res.Err != errAddressRequired { t.Fatalf("Expected '%s' error, but got '%s'", errAddressRequired, res.Err) } res = CreateAssociateMember(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", MemberCreateOpts{Address: "1.2.3.4"}) if res.Err == nil || res.Err != errProtocolPortRequired { t.Fatalf("Expected '%s' error, but got '%s'", errProtocolPortRequired, res.Err) } }
func TestList(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/extensions", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) w.Header().Add("Content-Type", "application/json") fmt.Fprintf(w, ` { "extensions": [ { "updated": "2013-01-20T00:00:00-00:00", "name": "Neutron Service Type Management", "links": [], "namespace": "http://docs.openstack.org/ext/neutron/service-type/api/v1.0", "alias": "service-type", "description": "API for retrieving service providers for Neutron advanced services" } ] } `) }) count := 0 List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { count++ actual, err := ExtractExtensions(page) if err != nil { t.Errorf("Failed to extract extensions: %v", err) } expected := []Extension{ Extension{ common.Extension{ Updated: "2013-01-20T00:00:00-00:00", Name: "Neutron Service Type Management", Links: []interface{}{}, Namespace: "http://docs.openstack.org/ext/neutron/service-type/api/v1.0", Alias: "service-type", Description: "API for retrieving service providers for Neutron advanced services", }, }, } th.AssertDeepEquals(t, expected, actual) return true, nil }) if count != 1 { t.Errorf("Expected 1 page, got %d", count) } }
func TestRequiredCreateOpts(t *testing.T) { res := Create(fake.ServiceClient(), CreateOpts{Direction: "something"}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{Direction: DirIngress, EtherType: "something"}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{Direction: DirIngress, EtherType: Ether4}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{Direction: DirIngress, EtherType: Ether4, SecGroupID: "something", Protocol: "foo"}) if res.Err == nil { t.Fatalf("Expected error, got none") } }
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 := Create(fake.ServiceClient(), 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) }
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": 3, "timeout": 20, "max_retries": 10, "url_path": "/another_check", "expected_codes": "301" } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusAccepted) fmt.Fprintf(w, ` { "health_monitor": { "admin_state_up": true, "tenant_id": "4fd44f30292945e481c7b8a0c8908869", "delay": 3, "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 := Update(fake.ServiceClient(), "b05e44b5-81f9-4551-b474-711a722698f7", UpdateOpts{ Delay: 3, Timeout: 20, MaxRetries: 10, URLPath: "/another_check", ExpectedCodes: "301", }).Extract() th.AssertNoErr(t, err) }
func TestRequiredCreateOpts(t *testing.T) { res := Create(fake.ServiceClient(), CreateOpts{}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{Name: "foo"}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{Name: "foo", Description: "bar"}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{Name: "foo", Description: "bar", VipAddress: "bar"}) if res.Err == nil { t.Fatalf("Expected error, got none") } }
func TestRequiredPoolCreateOpts(t *testing.T) { res := Create(fake.ServiceClient(), CreateOpts{}) if res.Err == nil { t.Fatalf("Expected error, got none") } res = Create(fake.ServiceClient(), CreateOpts{LBMethod: LBMethod("invalid"), Protocol: ProtocolHTTPS, LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a"}) if res.Err == nil || res.Err != errValidLBMethodRequired { t.Fatalf("Expected '%s' error, but got '%s'", errValidLBMethodRequired, res.Err) } res = Create(fake.ServiceClient(), CreateOpts{LBMethod: LBMethodRoundRobin, Protocol: Protocol("invalid"), LoadbalancerID: "69055154-f603-4a28-8951-7cc2d9e54a9a"}) if res.Err == nil || res.Err != errValidProtocolRequired { t.Fatalf("Expected '%s' error, but got '%s'", errValidProtocolRequired, res.Err) } res = Create(fake.ServiceClient(), CreateOpts{LBMethod: LBMethodRoundRobin, Protocol: ProtocolHTTPS}) if res.Err == nil || res.Err != errLoadbalancerOrListenerRequired { t.Fatalf("Expected '%s' error, but got '%s'", errLoadbalancerOrListenerRequired, res.Err) } }
func TestCreate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/routers", 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, ` { "router":{ "name": "foo_router", "admin_state_up": false, "external_gateway_info":{ "network_id":"8ca37218-28ff-41cb-9b10-039601ea7e6b" } } } `) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusCreated) fmt.Fprintf(w, ` { "router": { "status": "ACTIVE", "external_gateway_info": { "network_id": "8ca37218-28ff-41cb-9b10-039601ea7e6b" }, "name": "foo_router", "admin_state_up": false, "tenant_id": "6b96ff0cb17a4b859e1e575d221683d3", "distributed": false, "id": "8604a0de-7f6b-409a-a47c-a1cc7bc77b2e" } } `) }) asu := false gwi := GatewayInfo{NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b"} options := CreateOpts{ Name: "foo_router", AdminStateUp: &asu, GatewayInfo: &gwi, } r, err := Create(fake.ServiceClient(), options).Extract() th.AssertNoErr(t, err) th.AssertEquals(t, "foo_router", r.Name) th.AssertEquals(t, false, r.AdminStateUp) th.AssertDeepEquals(t, GatewayInfo{NetworkID: "8ca37218-28ff-41cb-9b10-039601ea7e6b"}, r.GatewayInfo) }
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 := CreateOpts{ Direction: "ingress", PortRangeMin: 80, EtherType: "IPv4", PortRangeMax: 80, Protocol: "tcp", RemoteGroupID: "85cc3048-abc3-43cc-89b3-377341426ac5", SecGroupID: "a7734e61-b545-452d-a3cd-0189cbd9747a", } _, err := Create(fake.ServiceClient(), opts).Extract() th.AssertNoErr(t, err) }
func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/v2.0/ports/46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, ` { "port": { "status": "ACTIVE", "name": "", "admin_state_up": true, "network_id": "a87cc70a-3e15-4acf-8205-9b711a3531b7", "tenant_id": "7e02058126cc4950b75f9970368ba177", "device_owner": "network:router_interface", "mac_address": "fa:16:3e:23:fd:d7", "fixed_ips": [ { "subnet_id": "a0304c3a-4f08-4c43-88af-d796509c97d2", "ip_address": "10.0.0.1" } ], "id": "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2", "security_groups": [], "device_id": "5e3898d7-11be-483e-9732-b2f5eccd2b2e", "binding:host_id": "HOST1", "binding:vnic_type": "normal" } } `) }) n, err := Get(fake.ServiceClient(), "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2").Extract() th.AssertNoErr(t, err) th.AssertEquals(t, n.Status, "ACTIVE") th.AssertEquals(t, n.Name, "") th.AssertEquals(t, n.AdminStateUp, true) th.AssertEquals(t, n.NetworkID, "a87cc70a-3e15-4acf-8205-9b711a3531b7") th.AssertEquals(t, n.TenantID, "7e02058126cc4950b75f9970368ba177") th.AssertEquals(t, n.DeviceOwner, "network:router_interface") th.AssertEquals(t, n.MACAddress, "fa:16:3e:23:fd:d7") th.AssertDeepEquals(t, n.FixedIPs, []IP{ {SubnetID: "a0304c3a-4f08-4c43-88af-d796509c97d2", IPAddress: "10.0.0.1"}, }) th.AssertEquals(t, n.ID, "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2") th.AssertDeepEquals(t, n.SecurityGroups, []string{}) th.AssertEquals(t, n.DeviceID, "5e3898d7-11be-483e-9732-b2f5eccd2b2e") th.AssertEquals(t, n.HostID, "HOST1") th.AssertEquals(t, n.VNICType, "normal") }