// CreateShareType will create a share type with a random name. An // error will be returned if the share type was unable to be created. func CreateShareType(t *testing.T, client *gophercloud.ServiceClient) (*sharetypes.ShareType, error) { if testing.Short() { t.Skip("Skipping test that requires share type creation in short mode.") } shareTypeName := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create share type: %s", shareTypeName) extraSpecsOps := sharetypes.ExtraSpecsOpts{ DriverHandlesShareServers: true, } createOpts := sharetypes.CreateOpts{ Name: shareTypeName, IsPublic: true, ExtraSpecs: extraSpecsOps, } shareType, err := sharetypes.Create(client, createOpts).Extract() if err != nil { return shareType, err } return shareType, nil }
// Verifies that a share type can't be created if the required parameters are missing func TestCreateFails(t *testing.T) { options := &sharetypes.CreateOpts{ Name: "my_new_share_type", } _, err := sharetypes.Create(client.ServiceClient(), options).Extract() if _, ok := err.(gophercloud.ErrMissingInput); !ok { t.Fatal("ErrMissingInput was expected to occur") } extraSpecs := sharetypes.ExtraSpecsOpts{ DriverHandlesShareServers: true, } options = &sharetypes.CreateOpts{ ExtraSpecs: extraSpecs, } _, err = sharetypes.Create(client.ServiceClient(), options).Extract() if _, ok := err.(gophercloud.ErrMissingInput); !ok { t.Fatal("ErrMissingInput was expected to occur") } }
// Verifies that a share type can be created correctly func TestCreate(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() MockCreateResponse(t) snapshotSupport := true extraSpecs := sharetypes.ExtraSpecsOpts{ DriverHandlesShareServers: true, SnapshotSupport: &snapshotSupport, } options := &sharetypes.CreateOpts{ Name: "my_new_share_type", IsPublic: true, ExtraSpecs: extraSpecs, } st, err := sharetypes.Create(client.ServiceClient(), options).Extract() th.AssertNoErr(t, err) th.AssertEquals(t, st.Name, "my_new_share_type") th.AssertEquals(t, st.IsPublic, true) }