Feature/filestorage sharenetworks get (#125)
* sfs: Add get for share networks
* sfs: Add acceptance test for share network Get
* sfs: Improve unit test for share network Get
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/requests.go b/openstack/sharedfilesystems/v2/sharenetworks/requests.go
index 0c7c5d3..700e703 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/requests.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/requests.go
@@ -116,3 +116,10 @@
return p
})
}
+
+// Get retrieves the ShareNetwork with the provided ID. To extract the ShareNetwork
+// object from the response, call the Extract method on the GetResult.
+func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
+ _, r.Err = client.Get(getURL(client, id), &r.Body, nil)
+ return
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/results.go b/openstack/sharedfilesystems/v2/sharenetworks/results.go
index 8086508..ce2b00b 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/results.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/results.go
@@ -137,3 +137,8 @@
type DeleteResult struct {
gophercloud.ErrResult
}
+
+// GetResult contains the response body and error from a Get request.
+type GetResult struct {
+ commonResult
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
index a99bb9a..1b3cb9b 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
@@ -223,3 +223,31 @@
}
})
}
+
+func MockGetResponse(t *testing.T) {
+ th.Mux.HandleFunc("/share-networks/7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd", 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, `
+ {
+ "share_network": {
+ "name": "net_my1",
+ "segmentation_id": null,
+ "created_at": "2015-09-04T14:56:45.000000",
+ "neutron_subnet_id": "53482b62-2c84-4a53-b6ab-30d9d9800d06",
+ "updated_at": null,
+ "id": "7f950b52-6141-4a08-bbb5-bb7ffa3ea5fd",
+ "neutron_net_id": "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
+ "ip_version": null,
+ "nova_net_id": null,
+ "cidr": null,
+ "project_id": "16e1ab15c35a457e9c2b2aa189f544e1",
+ "network_type": null,
+ "description": "descr"
+ }
+ }`)
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
index f13f1da..a66199f 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
@@ -138,3 +138,33 @@
th.AssertEquals(t, count, 3)
}
+
+// 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)
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/urls.go b/openstack/sharedfilesystems/v2/sharenetworks/urls.go
index 464c17a..9e2c8e9 100644
--- a/openstack/sharedfilesystems/v2/sharenetworks/urls.go
+++ b/openstack/sharedfilesystems/v2/sharenetworks/urls.go
@@ -13,3 +13,7 @@
func listDetailURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL("share-networks", "detail")
}
+
+func getURL(c *gophercloud.ServiceClient, id string) string {
+ return deleteURL(c, id)
+}