Feature/filestorage sharenetworks create (#118)
* sfs: Add support for share networks Create
* sfs: Add Manila to acceptance test environment
* sfs: Add acceptance tests for share networks Create
* sfs: Remove unused urls
Some url functions were introduced but they belong to other
PRs. Will be repushed with in the correct PRs
* sfs: Make name and descr required for creating share network
* sfs: Remove required parameters
After taking a close look at the code it appeared that 'name'
and 'description' are not required parameters
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
new file mode 100644
index 0000000..bc61084
--- /dev/null
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/fixtures.go
@@ -0,0 +1,63 @@
+package testing
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ th "github.com/gophercloud/gophercloud/testhelper"
+ fake "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+func createReq(name, description, network, subnetwork string) string {
+ return fmt.Sprintf(`{
+ "share_network": {
+ "name": "%s",
+ "description": "%s",
+ "neutron_net_id": "%s",
+ "neutron_subnet_id": "%s"
+ }
+ }`, name, description, network, subnetwork)
+}
+
+func createResp(name, description, network, subnetwork string) string {
+ return fmt.Sprintf(`
+ {
+ "share_network": {
+ "name": "%s",
+ "description": "%s",
+ "segmentation_id": null,
+ "created_at": "2015-09-07T14:37:00.583656",
+ "updated_at": null,
+ "id": "77eb3421-4549-4789-ac39-0d5185d68c29",
+ "neutron_net_id": "%s",
+ "neutron_subnet_id": "%s",
+ "ip_version": null,
+ "nova_net_id": null,
+ "cidr": null,
+ "project_id": "e10a683c20da41248cfd5e1ab3d88c62",
+ "network_type": null
+ }
+ }`, name, description, network, subnetwork)
+}
+
+func MockCreateResponse(t *testing.T) {
+ th.Mux.HandleFunc("/share-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, createReq("my_network",
+ "This is my share network",
+ "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
+ "53482b62-2c84-4a53-b6ab-30d9d9800d06"))
+
+ w.Header().Add("Content-Type", "application/json")
+ w.WriteHeader(http.StatusAccepted)
+
+ fmt.Fprintf(w, createResp("my_network",
+ "This is my share network",
+ "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
+ "53482b62-2c84-4a53-b6ab-30d9d9800d06"))
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
new file mode 100644
index 0000000..9a00885
--- /dev/null
+++ b/openstack/sharedfilesystems/v2/sharenetworks/testing/requests_test.go
@@ -0,0 +1,32 @@
+package testing
+
+import (
+ "testing"
+
+ "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks"
+ th "github.com/gophercloud/gophercloud/testhelper"
+ "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+// Verifies that a share network can be created correctly
+func TestCreate(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockCreateResponse(t)
+
+ options := &sharenetworks.CreateOpts{
+ Name: "my_network",
+ Description: "This is my share network",
+ NeutronNetID: "998b42ee-2cee-4d36-8b95-67b5ca1f2109",
+ NeutronSubnetID: "53482b62-2c84-4a53-b6ab-30d9d9800d06",
+ }
+
+ n, err := sharenetworks.Create(client.ServiceClient(), options).Extract()
+ th.AssertNoErr(t, err)
+
+ th.AssertEquals(t, n.Name, "my_network")
+ th.AssertEquals(t, n.Description, "This is my share network")
+ th.AssertEquals(t, n.NeutronNetID, "998b42ee-2cee-4d36-8b95-67b5ca1f2109")
+ th.AssertEquals(t, n.NeutronSubnetID, "53482b62-2c84-4a53-b6ab-30d9d9800d06")
+}