func TestList(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleListExtensionsSuccessfully(t) count := 0 extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { count++ actual, err := extensions.ExtractExtensions(page) th.AssertNoErr(t, err) expected := []common.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 }) th.CheckEquals(t, 1, count) }
func TestListMembers(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleMemberListSuccessfully(t) pages := 0 err := pools.ListMembers(fake.ServiceClient(), "332abe93-f488-41ba-870b-2ac66be7f853", pools.ListMembersOpts{}).EachPage(func(page pagination.Page) (bool, error) { pages++ actual, err := pools.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 tokenPost(t *testing.T, options gophercloud.AuthOptions, requestJSON string) tokens.CreateResult { th.SetupHTTP() defer th.TeardownHTTP() HandleTokenPost(t, requestJSON) return tokens.Create(client.ServiceClient(), options) }
// Verifies that it is possible to get a share network func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockGetResponse(t) var nilTime time.Time expected := sharenetworks.ShareNetwork{ ID: "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd", Name: "net_my1", CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 56, 45, 0, time.UTC)), Description: "descr", NetworkType: "", CIDR: "", NovaNetID: "", NeutronNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109", NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06", IPVersion: 0, SegmentationID: 0, UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime), ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", } n, err := sharenetworks.Get(client.ServiceClient(), "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd").Extract() th.AssertNoErr(t, err) th.CheckDeepEquals(t, &expected, n) }
func TestListImage(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleImageListSuccessfully(t) t.Logf("Test setup %+v\n", th.Server) t.Logf("Id\tName\tOwner\tChecksum\tSizeBytes") pager := images.List(fakeclient.ServiceClient(), images.ListOpts{Limit: 1}) t.Logf("Pager state %v", pager) count, pages := 0, 0 err := pager.EachPage(func(page pagination.Page) (bool, error) { pages++ t.Logf("Page %v", page) images, err := images.ExtractImages(page) if err != nil { return false, err } for _, i := range images { t.Logf("%s\t%s\t%s\t%s\t%v\t\n", i.ID, i.Name, i.Owner, i.Checksum, i.SizeBytes) count++ } return true, nil }) th.AssertNoErr(t, err) t.Logf("--------\n%d images listed on %d pages.\n", count, pages) th.AssertEquals(t, 3, pages) th.AssertEquals(t, 3, count) }
func TestGetHomeDocument(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleGetSuccessfully(t) actual, err := base.Get(fake.ServiceClient()).Extract() th.CheckNoErr(t, err) expected := base.HomeDocument{ "rel/cdn": map[string]interface{}{ "href-template": "services{?marker,limit}", "href-vars": map[string]interface{}{ "marker": "param/marker", "limit": "param/limit", }, "hints": map[string]interface{}{ "allow": []string{"GET"}, "formats": map[string]interface{}{ "application/json": map[string]interface{}{}, }, }, }, } th.CheckDeepEquals(t, expected, *actual) }
// Verifies that share types can be listed correctly func TestList(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockListResponse(t) allPages, err := sharetypes.List(client.ServiceClient(), &sharetypes.ListOpts{}).AllPages() th.AssertNoErr(t, err) actual, err := sharetypes.ExtractShareTypes(allPages) th.AssertNoErr(t, err) expected := []sharetypes.ShareType{ { ID: "be27425c-f807-4500-a056-d00721db45cf", Name: "default", IsPublic: true, ExtraSpecs: map[string]interface{}{"snapshot_support": "True", "driver_handles_share_servers": "True"}, RequiredExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "True"}, }, { ID: "f015bebe-c38b-4c49-8832-00143b10253b", Name: "d", IsPublic: true, ExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "false", "snapshot_support": "True"}, RequiredExtraSpecs: map[string]interface{}{"driver_handles_share_servers": "True"}, }, } th.CheckDeepEquals(t, expected, actual) }
func TestMemberUpdateSuccessfully(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() counter := HandleImageMemberUpdate(t) im, err := members.Update(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", "8989447062e04a818baf9e073fd04fa7", members.UpdateOpts{ Status: "accepted", }).Extract() th.AssertEquals(t, 1, counter.Counter) th.AssertNoErr(t, err) createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") th.AssertNoErr(t, err) updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") th.AssertNoErr(t, err) th.AssertDeepEquals(t, members.Member{ CreatedAt: createdAt, ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", MemberID: "8989447062e04a818baf9e073fd04fa7", Schema: "/v2/schemas/member", Status: "accepted", UpdatedAt: updatedAt, }, *im) }
func TestCreateMemberSuccessfully(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleCreateImageMemberSuccessfully(t) im, err := members.Create(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", "8989447062e04a818baf9e073fd04fa7").Extract() th.AssertNoErr(t, err) createdAt, err := time.Parse(time.RFC3339, createdAtString) th.AssertNoErr(t, err) updatedAt, err := time.Parse(time.RFC3339, updatedAtString) th.AssertNoErr(t, err) th.AssertDeepEquals(t, members.Member{ CreatedAt: createdAt, ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", MemberID: "8989447062e04a818baf9e073fd04fa7", Schema: "/v2/schemas/member", Status: "pending", UpdatedAt: updatedAt, }, *im) }
func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() th.Mux.HandleFunc("/networks/d32019d3-bc6e-4319-9c1d-6722fc136a22", 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, ` { "network": { "admin_state_up": true, "id": "8d05a1b1-297a-46ca-8974-17debf51ca3c", "name": "ext_net", "router:external": true, "shared": false, "status": "ACTIVE", "subnets": [ "2f1fb918-9b0e-4bf9-9a50-6cebbb4db2c5" ], "tenant_id": "5eb8995cf717462c9df8d1edfa498010" } } `) }) res := networks.Get(fake.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") n, err := external.ExtractGet(res) th.AssertNoErr(t, err) th.AssertEquals(t, true, n.External) }
func TestShowMemberDetails(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleImageMemberDetails(t) md, err := members.Get(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", "8989447062e04a818baf9e073fd04fa7").Extract() th.AssertNoErr(t, err) if md == nil { t.Errorf("Expected non-nil value for md") } createdAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") th.AssertNoErr(t, err) updatedAt, err := time.Parse(time.RFC3339, "2013-11-26T07:21:21Z") th.AssertNoErr(t, err) th.AssertDeepEquals(t, members.Member{ CreatedAt: createdAt, ImageID: "da3b75d9-3f4a-40e7-8a2c-bfab23927dea", MemberID: "8989447062e04a818baf9e073fd04fa7", Schema: "/v2/schemas/member", Status: "pending", UpdatedAt: updatedAt, }, *md) }
func TestListServers(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleServerListSuccessfully(t) pages := 0 err := servers.List(client.ServiceClient(), servers.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { pages++ actual, err := servers.ExtractServers(page) if err != nil { return false, err } if len(actual) != 3 { t.Fatalf("Expected 3 servers, got %d", len(actual)) } th.CheckDeepEquals(t, ServerHerp, actual[0]) th.CheckDeepEquals(t, ServerDerp, actual[1]) th.CheckDeepEquals(t, ServerMerp, actual[2]) return true, nil }) th.AssertNoErr(t, err) if pages != 1 { t.Errorf("Expected 1 page, saw %d", pages) } }
// test the fetch function func TestFetch(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() baseurl, err := getBasePath() th.AssertNoErr(t, err) fakeURL := strings.Join([]string{baseurl, "file.yaml"}, "/") urlparsed, err := url.Parse(fakeURL) th.AssertNoErr(t, err) th.Mux.HandleFunc(urlparsed.Path, func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") w.Header().Set("Content-Type", "application/jason") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Fee-fi-fo-fum") }) client := fakeClient{BaseClient: getHTTPClient()} te := TE{ URL: "file.yaml", client: client, } err = te.Fetch() th.AssertNoErr(t, err) th.AssertEquals(t, fakeURL, te.URL) th.AssertEquals(t, "Fee-fi-fo-fum", string(te.Bin)) }
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 := extensions.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 TestListFlavors(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleList(t) pages := 0 err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { pages++ actual, err := flavors.ExtractFlavors(page) if err != nil { return false, err } expected := []flavors.Flavor{ { ID: 1, Name: "m1.tiny", RAM: 512, Links: []gophercloud.Link{ {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"}, {Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"}, }, }, { ID: 2, Name: "m1.small", RAM: 1024, Links: []gophercloud.Link{ {Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"}, {Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"}, }, }, { ID: 3, Name: "m1.medium", RAM: 2048, Links: []gophercloud.Link{ {Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"}, {Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"}, }, }, { ID: 4, Name: "m1.large", RAM: 4096, Links: []gophercloud.Link{ {Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"}, {Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"}, }, }, } th.AssertDeepEquals(t, expected, actual) return true, nil }) th.AssertNoErr(t, err) th.AssertEquals(t, 1, pages) }
func TestMemberListEmpty(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleImageMemberEmptyList(t) pager := members.List(fakeclient.ServiceClient(), "da3b75d9-3f4a-40e7-8a2c-bfab23927dea") t.Logf("Pager state %v", pager) count, pages := 0, 0 err := pager.EachPage(func(page pagination.Page) (bool, error) { pages++ t.Logf("Page %v", page) members, err := members.ExtractMembers(page) if err != nil { return false, err } for _, i := range members { t.Logf("%s\t%s\t%s\t%s\t\n", i.ImageID, i.MemberID, i.Status, i.Schema) count++ } return true, nil }) th.AssertNoErr(t, err) th.AssertEquals(t, 0, pages) th.AssertEquals(t, 0, count) }
func TestList(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleList(t) expectedDBs := []databases.Database{ {Name: "anotherexampledb"}, {Name: "exampledb"}, {Name: "nextround"}, {Name: "sampledb"}, {Name: "testingdb"}, } pages := 0 err := databases.List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { pages++ actual, err := databases.ExtractDBs(page) if err != nil { return false, err } th.CheckDeepEquals(t, expectedDBs, actual) return true, nil }) th.AssertNoErr(t, err) if pages != 1 { t.Errorf("Expected 1 page, saw %d", pages) } }
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 TestListAll(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockListResponse(t) allPages, err := volumes.List(client.ServiceClient(), &volumes.ListOpts{}).AllPages() th.AssertNoErr(t, err) actual, err := volumes.ExtractVolumes(allPages) th.AssertNoErr(t, err) expected := []volumes.Volume{ { ID: "289da7f8-6440-407c-9fb4-7db01ec49164", Name: "vol-001", }, { ID: "96c3bda7-c82a-4f50-be73-ca7621794835", Name: "vol-002", }, } th.CheckDeepEquals(t, expected, actual) }
// Verifies that a security service can be created correctly func TestCreate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockCreateResponse(t) options := &securityservices.CreateOpts{ Name: "SecServ1", Description: "Creating my first Security Service", DNSIP: "10.0.0.0/24", User: "******", Password: "******", Type: "kerberos", } s, err := securityservices.Create(client.ServiceClient(), options).Extract() th.AssertNoErr(t, err) th.AssertEquals(t, s.Name, "SecServ1") th.AssertEquals(t, s.Description, "Creating my first Security Service") th.AssertEquals(t, s.User, "demo") th.AssertEquals(t, s.DNSIP, "10.0.0.0/24") th.AssertEquals(t, s.Password, "supersecret") th.AssertEquals(t, s.Type, "kerberos") }
// Verifies that share networks list can be called with query parameters func TestPaginatedListDetail(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockFilteredListResponse(t) options := &sharenetworks.ListOpts{ Offset: 0, Limit: 1, } count := 0 err := sharenetworks.ListDetail(client.ServiceClient(), options).EachPage(func(page pagination.Page) (bool, error) { count++ _, err := sharenetworks.ExtractShareNetworks(page) if err != nil { t.Errorf("Failed to extract share networks: %v", err) return false, err } return true, nil }) th.AssertNoErr(t, err) th.AssertEquals(t, count, 3) }
func TestCreate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleCreate(t) opts := users.BatchCreateOpts{ { Databases: db.BatchCreateOpts{ db.CreateOpts{Name: "databaseA"}, }, Name: "dbuser3", Password: "******", }, { Databases: db.BatchCreateOpts{ {Name: "databaseB"}, {Name: "databaseC"}, }, Name: "dbuser4", Password: "******", }, } res := users.Create(fake.ServiceClient(), instanceID, opts) th.AssertNoErr(t, res.Err) }
// Verifies that it is possible to update a share network using nova network func TestUpdateNova(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockUpdateNovaResponse(t) expected := sharenetworks.ShareNetwork{ ID: "713df749-aac0-4a54-af52-10f6c991e80c", Name: "net_my2", CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 4, 14, 54, 25, 0, time.UTC)), Description: "new description", NetworkType: "", CIDR: "", NovaNetID: "new-nova-id", NeutronNetID: "", NeutronSubnetID: "", IPVersion: 4, SegmentationID: 0, UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2015, 9, 7, 8, 2, 53, 512184000, time.UTC)), ProjectID: "16e1ab15c35a457e9c2b2aa189f544e1", } options := sharenetworks.UpdateOpts{ Name: "net_my2", Description: "new description", NovaNetID: "new-nova-id", } v, err := sharenetworks.Update(client.ServiceClient(), "713df749-aac0-4a54-af52-10f6c991e80c", options).Extract() th.AssertNoErr(t, err) th.CheckDeepEquals(t, &expected, v) }
func TestUpdate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleUpdate(t) options := portsbinding.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 := portsbinding.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 TestListPools(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandlePoolListSuccessfully(t) pages := 0 err := pools.List(fake.ServiceClient(), pools.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { pages++ actual, err := pools.ExtractPools(page) if err != nil { return false, err } if len(actual) != 2 { t.Fatalf("Expected 2 pools, got %d", len(actual)) } th.CheckDeepEquals(t, PoolWeb, actual[0]) th.CheckDeepEquals(t, PoolDb, actual[1]) return true, nil }) th.AssertNoErr(t, err) if pages != 1 { t.Errorf("Expected 1 page, saw %d", pages) } }
func TestGet(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleGet(t) n, err := portsbinding.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 TestChooseVersionFromSuffix(t *testing.T) { testhelper.SetupHTTP() defer testhelper.TeardownHTTP() v2 := &utils.Version{ID: "v2.0", Priority: 2, Suffix: "/v2.0/"} v3 := &utils.Version{ID: "v3.0", Priority: 3, Suffix: "/v3.0/"} c := &gophercloud.ProviderClient{ IdentityBase: testhelper.Endpoint(), IdentityEndpoint: testhelper.Endpoint() + "v2.0/", } v, endpoint, err := utils.ChooseVersion(c, []*utils.Version{v2, v3}) if err != nil { t.Fatalf("Unexpected error from ChooseVersion: %v", err) } if v != v2 { t.Errorf("Expected %#v to win, but %#v did instead", v2, v) } expected := testhelper.Endpoint() + "v2.0/" if endpoint != expected { t.Errorf("Expected endpoint [%s], but was [%s] instead", expected, endpoint) } }
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 TestRole(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockListRoleResponse(t) count := 0 err := roles.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { count++ actual, err := roles.ExtractRoles(page) if err != nil { t.Errorf("Failed to extract users: %v", err) return false, err } expected := []roles.Role{ { ID: "123", Name: "compute:admin", Description: "Nova Administrator", }, } th.CheckDeepEquals(t, expected, actual) return true, nil }) th.AssertNoErr(t, err) th.AssertEquals(t, 1, count) }
func TestCreateICMPZero(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() mockCreateRuleResponseICMPZero(t) opts := defsecrules.CreateOpts{ IPProtocol: "ICMP", FromPort: 0, ToPort: 0, CIDR: "10.10.12.0/24", } group, err := defsecrules.Create(client.ServiceClient(), opts).Extract() th.AssertNoErr(t, err) expected := &defsecrules.DefaultRule{ ID: ruleID, FromPort: 0, ToPort: 0, IPProtocol: "ICMP", IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"}, } th.AssertDeepEquals(t, expected, group) }