Moving extensions and API versions into different sub-packages; fixing test helper methods
diff --git a/openstack/networking/v2/networks/requests.go b/openstack/networking/v2/networks/requests.go
index 9a23cc0..06b0fe7 100644
--- a/openstack/networking/v2/networks/requests.go
+++ b/openstack/networking/v2/networks/requests.go
@@ -5,48 +5,11 @@
"github.com/rackspace/gophercloud"
)
-func APIVersions(c *gophercloud.ServiceClient) (*APIVersionsList, error) {
- var resp APIVersionsList
- _, err := perigee.Request("GET", APIVersionsURL(c), perigee.Options{
- MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &resp,
- OkCodes: []int{200},
- })
- if err != nil {
- return nil, err
- }
-
- return &resp, nil
-}
-
-func APIInfo(c *gophercloud.ServiceClient, v string) (*APIInfoList, error) {
- var resp APIInfoList
- _, err := perigee.Request("GET", APIInfoURL(c, v), perigee.Options{
- MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &resp,
- OkCodes: []int{200},
- })
- if err != nil {
- return nil, err
- }
-
- return &resp, nil
-}
-
-func GetExtension(c *gophercloud.ServiceClient, name string) (*Extension, error) {
- var ext Extension
- _, err := perigee.Request("GET", ExtensionURL(c, name), perigee.Options{
- MoreHeaders: c.Provider.AuthenticatedHeaders(),
- Results: &struct {
- Extension *Extension `json:"extension"`
- }{&ext},
- OkCodes: []int{200},
- })
-
- if err != nil {
- return nil, err
- }
- return &ext, nil
+type NetworkOpts struct {
+ AdminStateUp bool
+ Name string
+ Shared *bool
+ TenantID string
}
func Get(c *gophercloud.ServiceClient, id string) (*NetworkResult, error) {
@@ -64,13 +27,6 @@
return &n, nil
}
-type NetworkOpts struct {
- AdminStateUp bool
- Name string
- Shared *bool
- TenantID string
-}
-
func Create(c *gophercloud.ServiceClient, opts NetworkOpts) (*NetworkCreateResult, error) {
// Define structures
type network struct {
diff --git a/openstack/networking/v2/networks/requests_test.go b/openstack/networking/v2/networks/requests_test.go
index c1d9c9f..6fa8222 100644
--- a/openstack/networking/v2/networks/requests_test.go
+++ b/openstack/networking/v2/networks/requests_test.go
@@ -20,166 +20,7 @@
}
}
-func TestListAPIVersions(t *testing.T) {
- th.SetupHTTP()
- defer th.TeardownHTTP()
-
- th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
-
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
-
- fmt.Fprintf(w, `
-{
- "versions": [
- {
- "status": "CURRENT",
- "id": "v2.0",
- "links": [
- {
- "href": "http://23.253.228.211:9696/v2.0",
- "rel": "self"
- }
- ]
- }
- ]
-}`)
- })
-
- c := ServiceClient()
-
- res, err := APIVersions(c)
- th.AssertNoErr(err)
-
- coll, err := gophercloud.AllPages(res)
- th.AssertNoErr(err)
-
- actual := ToAPIVersions(coll)
-
- expected := []APIVersion{
- APIVersion{
- Status: "CURRENT",
- ID: "v2.0",
- },
- }
- th.AssertDeepEquals(expected, actual)
-}
-
-func TestAPIInfo(t *testing.T) {
- th.SetupHTTP()
- defer th.TeardownHTTP()
-
- th.Mux.HandleFunc("/v2.0/", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
-
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
-
- fmt.Fprintf(w, `
-{
- "resources": [
- {
- "links": [
- {
- "href": "http://23.253.228.211:9696/v2.0/subnets",
- "rel": "self"
- }
- ],
- "name": "subnet",
- "collection": "subnets"
- },
- {
- "links": [
- {
- "href": "http://23.253.228.211:9696/v2.0/networks",
- "rel": "self"
- }
- ],
- "name": "network",
- "collection": "networks"
- },
- {
- "links": [
- {
- "href": "http://23.253.228.211:9696/v2.0/ports",
- "rel": "self"
- }
- ],
- "name": "port",
- "collection": "ports"
- }
- ]
-}
- `)
- })
-
- res, err := APIInfo(ServiceClient(), "v2.0")
- th.AssertNoErr(err)
-
- coll, err := gophercloud.AllPages(res)
- th.AssertNoErr(err)
-
- actual := ToAPIResource(coll)
- expected := []APIResource{
- APIResource{
- Name: "subnet",
- Collection: "subnets",
- },
- APIResource{
- Name: "network",
- Collection: "networks",
- },
- APIResource{
- Name: "port",
- Collection: "ports",
- },
- }
- th.AssertDeepEquals(expected, actual)
-}
-
-func TestListingExtensions(t *testing.T) {
-
-}
-
-func TestGettingExtension(t *testing.T) {
- th.SetupHTTP()
- defer th.TeardownHTTP()
-
- th.Mux.HandleFunc("/v2.0/extension/agent", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", 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 := GetExtension(ServiceClient(), "agent")
- 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 TestGettingNetwork(t *testing.T) {
+func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -212,7 +53,7 @@
})
n, err := Get(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
- th.AssertNoErr(err)
+ th.AssertNoErr(t, err)
th.AssertEquals(t, n.Status, "ACTIVE")
th.AssertDeepEquals(t, n.Subnets, []interface{}{"54d6f61d-db07-451c-9ab3-b9609b6b6f0b"})
@@ -227,7 +68,7 @@
th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
}
-func TestCreateNetwork(t *testing.T) {
+func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -278,7 +119,7 @@
options := NetworkOpts{Name: "sample_network", AdminStateUp: true}
n, err := Create(ServiceClient(), options)
- th.AssertNoErr(err)
+ th.AssertNoErr(t, err)
th.AssertEquals(t, n.Status, "ACTIVE")
th.AssertDeepEquals(t, n.Subnets, []interface{}{})
@@ -294,7 +135,7 @@
th.AssertEquals(t, n.ID, "4e8e5957-649f-477b-9e5b-f1f75b21c03c")
}
-func TestCreateNetworkWithOptionalFields(t *testing.T) {
+func TestCreateWithOptionalFields(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -320,10 +161,10 @@
shared := true
options := NetworkOpts{Name: "sample_network", AdminStateUp: true, Shared: &shared, TenantID: "12345"}
_, err := Create(ServiceClient(), options)
- th.AssertNoErr(err)
+ th.AssertNoErr(t, err)
}
-func TestUpdateNetwork(t *testing.T) {
+func TestUpdate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -367,7 +208,7 @@
shared := true
options := NetworkOpts{Name: "new_network_name", AdminStateUp: false, Shared: &shared}
n, err := Update(ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c", options)
- th.AssertNoErr(err)
+ th.AssertNoErr(t, err)
th.AssertEquals(t, n.Name, "new_network_name")
th.AssertEquals(t, n.AdminStateUp, false)
@@ -375,7 +216,7 @@
th.AssertEquals(t, n.ID, "4e8e5957-649f-477b-9e5b-f1f75b21c03c")
}
-func TestDeleteNetwork(t *testing.T) {
+func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
@@ -386,5 +227,5 @@
})
err := Delete(ServiceClient(), "4e8e5957-649f-477b-9e5b-f1f75b21c03c")
- th.AssertNoErr(err)
+ th.AssertNoErr(t, err)
}
diff --git a/openstack/networking/v2/networks/results.go b/openstack/networking/v2/networks/results.go
index 741a959..4678793 100644
--- a/openstack/networking/v2/networks/results.go
+++ b/openstack/networking/v2/networks/results.go
@@ -1,12 +1,5 @@
package networks
-import (
- "fmt"
-
- "github.com/mitchellh/mapstructure"
- "github.com/rackspace/gophercloud"
-)
-
type NetworkProvider struct {
ProviderSegmentationID int `json:"provider:segmentation_id"`
ProviderPhysicalNetwork string `json:"provider:physical_network"`
@@ -34,108 +27,3 @@
Segments []NetworkProvider `json:"segments"`
PortSecurityEnabled bool `json:"port_security_enabled"`
}
-
-type APIVersion struct {
- Status string
- ID string
-}
-
-type APIVersionsList struct {
- gophercloud.PaginationLinks `json:"links"`
- Client *gophercloud.ServiceClient
- APIVersions []APIVersion `json:"versions"`
-}
-
-func (list APIVersionsList) Pager() gophercloud.Pager {
- return gophercloud.NewLinkPager(list)
-}
-
-func (list APIVersionsList) Concat(other gophercloud.Collection) gophercloud.Collection {
- return APIVersionsList{
- Client: list.Client,
- APIVersions: append(list.APIVersions, ToAPIVersions(other)...),
- }
-}
-
-func (list APIVersionsList) Service() *gophercloud.ServiceClient {
- return list.Client
-}
-
-func (list APIVersionsList) Links() gophercloud.PaginationLinks {
- return list.PaginationLinks
-}
-
-func (list APIVersionsList) Interpret(json interface{}) (gophercloud.LinkCollection, error) {
- mapped, ok := json.(map[string]interface{})
- if !ok {
- return nil, fmt.Errorf("Unexpected JSON response: %#v", json)
- }
-
- var result APIVersionsList
- err := mapstructure.Decode(mapped, &result)
- if err != nil {
- return nil, err
- }
- return result, nil
-}
-
-func ToAPIVersions(results gophercloud.Collection) []APIVersion {
- return results.(*APIVersionsList).APIVersions
-}
-
-type APIResource struct {
- Name string
- Collection string
-}
-
-type APIInfoList struct {
- gophercloud.PaginationLinks `json:"links"`
- Client *gophercloud.ServiceClient
- APIResources []APIResource `json:"resources"`
-}
-
-func (list APIInfoList) Pager() gophercloud.Pager {
- return gophercloud.NewLinkPager(list)
-}
-
-func (list APIInfoList) Concat(other gophercloud.Collection) gophercloud.Collection {
- return APIInfoList{
- Client: list.Client,
- APIResources: append(list.APIResources, ToAPIResource(other)...),
- }
-}
-
-func (list APIInfoList) Service() *gophercloud.ServiceClient {
- return list.Client
-}
-
-func (list APIInfoList) Links() gophercloud.PaginationLinks {
- return list.PaginationLinks
-}
-
-func (list APIInfoList) Interpret(json interface{}) (gophercloud.LinkCollection, error) {
- mapped, ok := json.(map[string]interface{})
- if !ok {
- return nil, fmt.Errorf("Unexpected JSON response: %#v", json)
- }
-
- var result APIInfoList
- err := mapstructure.Decode(mapped, &result)
- if err != nil {
- return nil, err
- }
- return result, nil
-}
-
-func ToAPIResource(results gophercloud.Collection) []APIResource {
- return results.(*APIInfoList).APIResources
-}
-
-type Extension struct {
- Updated string `json:"updated"`
- Name string `json:"name"`
- Links []interface{} `json:"links"`
- Namespace string `json:"namespace"`
- Alias string `json:"alias"`
- Description string `json:"description"`
-}
diff --git a/openstack/networking/v2/networks/urls.go b/openstack/networking/v2/networks/urls.go
index 0b0b70e..13fcc03 100644
--- a/openstack/networking/v2/networks/urls.go
+++ b/openstack/networking/v2/networks/urls.go
@@ -1,25 +1,9 @@
package networks
-import (
- "strings"
-
- "github.com/rackspace/gophercloud"
-)
+import "github.com/rackspace/gophercloud"
const Version = "v2.0"
-func APIVersionsURL(c *gophercloud.ServiceClient) string {
- return c.ServiceURL("")
-}
-
-func APIInfoURL(c *gophercloud.ServiceClient, version string) string {
- return c.ServiceURL(strings.TrimRight(version, "/") + "/")
-}
-
-func ExtensionURL(c *gophercloud.ServiceClient, name string) string {
- return c.ServiceURL(Version, "extensions", name)
-}
-
func NetworkURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL(Version, "networks", id)
}
diff --git a/openstack/networking/v2/networks/urls_test.go b/openstack/networking/v2/networks/urls_test.go
index 8533867..b8970a2 100644
--- a/openstack/networking/v2/networks/urls_test.go
+++ b/openstack/networking/v2/networks/urls_test.go
@@ -13,32 +13,14 @@
return &gophercloud.ServiceClient{Endpoint: Endpoint}
}
-func TestAPIVersionsURL(t *testing.T) {
- actual := APIVersionsURL(EndpointClient())
- expected := Endpoint
- th.AssertEquals(expected, actual)
-}
-
-func TestAPIInfoURL(t *testing.T) {
- actual := APIInfoURL(EndpointClient(), "v2.0")
- expected := Endpoint + "v2.0/"
- th.AssertEquals(expected, actual)
-}
-
-func TestExtensionURL(t *testing.T) {
- actual := ExtensionURL(EndpointClient(), "agent")
- expected := Endpoint + "v2.0/extensions/agent"
- th.AssertEquals(expected, actual)
-}
-
func TestNetworkURL(t *testing.T) {
actual := NetworkURL(EndpointClient(), "foo")
expected := Endpoint + "v2.0/networks/foo"
- th.AssertEquals(expected, actual)
+ th.AssertEquals(t, expected, actual)
}
func TestCreateURL(t *testing.T) {
actual := CreateURL(EndpointClient())
expected := Endpoint + "v2.0/networks"
- th.AssertEquals(expected, actual)
+ th.AssertEquals(t, expected, actual)
}