Moving extensions and API versions into different sub-packages; fixing test helper methods
diff --git a/openstack/networking/v2/extensions/doc.go b/openstack/networking/v2/extensions/doc.go
new file mode 100644
index 0000000..83c4a6a
--- /dev/null
+++ b/openstack/networking/v2/extensions/doc.go
@@ -0,0 +1 @@
+package networks
diff --git a/openstack/networking/v2/extensions/errors.go b/openstack/networking/v2/extensions/errors.go
new file mode 100644
index 0000000..83c4a6a
--- /dev/null
+++ b/openstack/networking/v2/extensions/errors.go
@@ -0,0 +1 @@
+package networks
diff --git a/openstack/networking/v2/extensions/requests.go b/openstack/networking/v2/extensions/requests.go
new file mode 100644
index 0000000..b406c51
--- /dev/null
+++ b/openstack/networking/v2/extensions/requests.go
@@ -0,0 +1,22 @@
+package networks
+
+import (
+ "github.com/racker/perigee"
+ "github.com/rackspace/gophercloud"
+)
+
+func Get(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
+}
diff --git a/openstack/networking/v2/extensions/requests_test.go b/openstack/networking/v2/extensions/requests_test.go
new file mode 100644
index 0000000..5ae7ec6
--- /dev/null
+++ b/openstack/networking/v2/extensions/requests_test.go
@@ -0,0 +1,60 @@
+package networks
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+const TokenID = "123"
+
+func ServiceClient() *gophercloud.ServiceClient {
+ return &gophercloud.ServiceClient{
+ Provider: &gophercloud.ProviderClient{
+ TokenID: TokenID,
+ },
+ Endpoint: th.Endpoint(),
+ }
+}
+
+func TestList(t *testing.T) {
+
+}
+
+func TestGet(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 := Get(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.")
+ })
+}
diff --git a/openstack/networking/v2/extensions/results.go b/openstack/networking/v2/extensions/results.go
new file mode 100644
index 0000000..3b21644
--- /dev/null
+++ b/openstack/networking/v2/extensions/results.go
@@ -0,0 +1,10 @@
+package networks
+
+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/extensions/urls.go b/openstack/networking/v2/extensions/urls.go
new file mode 100644
index 0000000..d70dd9b
--- /dev/null
+++ b/openstack/networking/v2/extensions/urls.go
@@ -0,0 +1,9 @@
+package networks
+
+import "github.com/rackspace/gophercloud"
+
+const Version = "v2.0"
+
+func ExtensionURL(c *gophercloud.ServiceClient, name string) string {
+ return c.ServiceURL(Version, "extensions", name)
+}
diff --git a/openstack/networking/v2/extensions/urls_test.go b/openstack/networking/v2/extensions/urls_test.go
new file mode 100644
index 0000000..af01cb9
--- /dev/null
+++ b/openstack/networking/v2/extensions/urls_test.go
@@ -0,0 +1,20 @@
+package networks
+
+import (
+ "testing"
+
+ "github.com/rackspace/gophercloud"
+ th "github.com/rackspace/gophercloud/testhelper"
+)
+
+const Endpoint = "http://localhost:57909/"
+
+func EndpointClient() *gophercloud.ServiceClient {
+ return &gophercloud.ServiceClient{Endpoint: Endpoint}
+}
+
+func TestExtensionURL(t *testing.T) {
+ actual := ExtensionURL(EndpointClient(), "agent")
+ expected := Endpoint + "v2.0/extensions/agent"
+ th.AssertEquals(t, expected, actual)
+}