github.com/leeclow-ops/gophercloud@v1.2.1/acceptance/openstack/sharedfilesystems/v2/sharetypes.go (about) 1 package v2 2 3 import ( 4 "testing" 5 6 "github.com/leeclow-ops/gophercloud" 7 "github.com/leeclow-ops/gophercloud/acceptance/tools" 8 "github.com/leeclow-ops/gophercloud/openstack/sharedfilesystems/v2/sharetypes" 9 ) 10 11 // CreateShareType will create a share type with a random name. An 12 // error will be returned if the share type was unable to be created. 13 func CreateShareType(t *testing.T, client *gophercloud.ServiceClient) (*sharetypes.ShareType, error) { 14 if testing.Short() { 15 t.Skip("Skipping test that requires share type creation in short mode.") 16 } 17 18 shareTypeName := tools.RandomString("ACPTTEST", 16) 19 t.Logf("Attempting to create share type: %s", shareTypeName) 20 21 extraSpecsOps := sharetypes.ExtraSpecsOpts{ 22 DriverHandlesShareServers: true, 23 } 24 25 createOpts := sharetypes.CreateOpts{ 26 Name: shareTypeName, 27 IsPublic: false, 28 ExtraSpecs: extraSpecsOps, 29 } 30 31 shareType, err := sharetypes.Create(client, createOpts).Extract() 32 if err != nil { 33 return shareType, err 34 } 35 36 return shareType, nil 37 } 38 39 // DeleteShareType will delete a share type. An error will occur if 40 // the share type was unable to be deleted. 41 func DeleteShareType(t *testing.T, client *gophercloud.ServiceClient, shareType *sharetypes.ShareType) { 42 err := sharetypes.Delete(client, shareType.ID).ExtractErr() 43 if err != nil { 44 t.Fatalf("Failed to delete share type %s: %v", shareType.ID, err) 45 } 46 47 t.Logf("Deleted share type: %s", shareType.ID) 48 }