Feature/filestorage sharetype getdefault (#144)
* sfs: Add support for share type Get Default
* sfs: Add acceptance tests for share type Get Default
* sfs: Improve share type Get Default unit tests
diff --git a/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go b/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
index 4f1787c..8784764 100644
--- a/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
+++ b/acceptance/openstack/sharedfilesystems/v2/sharetypes_test.go
@@ -43,3 +43,21 @@
PrintShareType(t, &shareType)
}
}
+
+func TestShareTypeGetDefault(t *testing.T) {
+ client, err := clients.NewSharedFileSystemV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a shared file system client: %v", err)
+ }
+
+ shareType, err := sharetypes.GetDefault(client).Extract()
+ if err != nil {
+ t.Fatalf("Unable to retrieve the default share type: %v", err)
+ }
+
+ if shareType.Name != "default" {
+ t.Fatal("Share type name was expected to be: default")
+ }
+
+ PrintShareType(t, shareType)
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/requests.go b/openstack/sharedfilesystems/v2/sharetypes/requests.go
index 1e63c5f..38174fe 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/requests.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/requests.go
@@ -92,3 +92,9 @@
return ShareTypePage{pagination.SinglePageBase(r)}
})
}
+
+// GetDefault will retrieve the default ShareType.
+func GetDefault(client *gophercloud.ServiceClient) (r GetDefaultResult) {
+ _, r.Err = client.Get(getDefaultURL(client), &r.Body, nil)
+ return
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/results.go b/openstack/sharedfilesystems/v2/sharetypes/results.go
index a48543e..fa3a4e1 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/results.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/results.go
@@ -63,3 +63,8 @@
err := (r.(ShareTypePage)).ExtractInto(&s)
return s.ShareTypes, err
}
+
+// GetDefaultResult contains the response body and error from a Get Default request.
+type GetDefaultResult struct {
+ commonResult
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go b/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
index 5cf7194..58d9bb3 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/testing/fixtures.go
@@ -133,3 +133,34 @@
}`)
})
}
+
+func MockGetDefaultResponse(t *testing.T) {
+ th.Mux.HandleFunc("/types/default", 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, `
+ {
+ "volume_type": {
+ "required_extra_specs": null,
+ "extra_specs": {
+ "snapshot_support": "True",
+ "driver_handles_share_servers": "True"
+ },
+ "name": "default",
+ "id": "be27425c-f807-4500-a056-d00721db45cf"
+ },
+ "share_type": {
+ "required_extra_specs": null,
+ "extra_specs": {
+ "snapshot_support": "True",
+ "driver_handles_share_servers": "True"
+ },
+ "name": "default",
+ "id": "be27425c-f807-4500-a056-d00721db45cf"
+ }
+ }`)
+ })
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go b/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
index ce20b0f..0518c02 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/testing/requests_test.go
@@ -100,3 +100,22 @@
th.CheckDeepEquals(t, expected, actual)
}
+
+// Verifies that it is possible to get the default share type
+func TestGetDefault(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ MockGetDefaultResponse(t)
+
+ expected := sharetypes.ShareType{
+ ID: "be27425c-f807-4500-a056-d00721db45cf",
+ Name: "default",
+ ExtraSpecs: map[string]interface{}{"snapshot_support": "True", "driver_handles_share_servers": "True"},
+ RequiredExtraSpecs: map[string]interface{}(nil),
+ }
+
+ actual, err := sharetypes.GetDefault(client.ServiceClient()).Extract()
+ th.AssertNoErr(t, err)
+ th.CheckDeepEquals(t, &expected, actual)
+}
diff --git a/openstack/sharedfilesystems/v2/sharetypes/urls.go b/openstack/sharedfilesystems/v2/sharetypes/urls.go
index 5004f97..7b1d2ca 100644
--- a/openstack/sharedfilesystems/v2/sharetypes/urls.go
+++ b/openstack/sharedfilesystems/v2/sharetypes/urls.go
@@ -13,3 +13,7 @@
func listURL(c *gophercloud.ServiceClient) string {
return createURL(c)
}
+
+func getDefaultURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL("types", "default")
+}