1package v1 2 3import ( 4 "testing" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/acceptance/tools" 8 "github.com/gophercloud/utils/gnocchi/metric/v1/resourcetypes" 9) 10 11// CreateResourceType creates Gnocchi resource type. An error will be returned if the 12// resource type could not be created. 13func CreateResourceType(t *testing.T, client *gophercloud.ServiceClient) (*resourcetypes.ResourceType, error) { 14 resourceTypeName := tools.RandomString("TESTACCT-", 8) 15 attributeStringName := tools.RandomString("TESTACCT-ATTRIBUTE-", 8) 16 attributeUUIDName := tools.RandomString("TESTACCT-ATTRIBUTE-", 8) 17 18 createOpts := resourcetypes.CreateOpts{ 19 Name: resourceTypeName, 20 Attributes: map[string]resourcetypes.AttributeOpts{ 21 attributeStringName: resourcetypes.AttributeOpts{ 22 Type: "string", 23 Details: map[string]interface{}{ 24 "max_length": 128, 25 "required": false, 26 }, 27 }, 28 attributeUUIDName: resourcetypes.AttributeOpts{ 29 Type: "uuid", 30 Details: map[string]interface{}{ 31 "required": true, 32 }, 33 }, 34 }, 35 } 36 t.Logf("Attempting to create a Gnocchi resource type") 37 38 resourceType, err := resourcetypes.Create(client, createOpts).Extract() 39 if err != nil { 40 return nil, err 41 } 42 43 t.Logf("Successfully created the Gnocchi resource type.") 44 return resourceType, nil 45} 46 47// DeleteResourceType deletes a Gnocchi resource type with the specified name. 48// A fatal error will occur if the delete was not successful. 49func DeleteResourceType(t *testing.T, client *gophercloud.ServiceClient, resourceTypeName string) { 50 t.Logf("Attempting to delete the Gnocchi resource type: %s", resourceTypeName) 51 52 err := resourcetypes.Delete(client, resourceTypeName).ExtractErr() 53 if err != nil { 54 t.Fatalf("Unable to delete the Gnocchi resource type %s: %v", resourceTypeName, err) 55 } 56 57 t.Logf("Deleted the Gnocchi resource type: %s", resourceTypeName) 58} 59