github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/kms/v1/grants_test.go (about) 1 package v1 2 3 import ( 4 "testing" 5 6 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 7 "github.com/opentelekomcloud/gophertelekomcloud/openstack/kms/v1/grants" 8 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 9 ) 10 11 func TestKmsGrantsLifecycle(t *testing.T) { 12 client, err := clients.NewKMSV1Client() 13 th.AssertNoErr(t, err) 14 15 kmsID := clients.EnvOS.GetEnv("KMS_ID") 16 if kmsID == "" { 17 t.Skip("OS_KMS_ID env var is missing but KMSv1 grant test requires") 18 } 19 20 createOpts := grants.CreateOpts{ 21 KeyID: kmsID, 22 GranteePrincipal: client.UserID, 23 Operations: []string{"describe-key", "create-datakey", "encrypt-datakey"}, 24 Name: "my_grant", 25 } 26 createGrant, err := grants.Create(client, createOpts).Extract() 27 th.AssertNoErr(t, err) 28 29 defer func() { 30 deleteOpts := grants.DeleteOpts{ 31 KeyID: kmsID, 32 GrantID: createGrant.GrantID, 33 } 34 th.AssertNoErr(t, grants.Delete(client, deleteOpts).ExtractErr()) 35 }() 36 37 listOpts := grants.ListOpts{ 38 KeyID: kmsID, 39 } 40 grantList, err := grants.List(client, listOpts).Extract() 41 th.AssertNoErr(t, err) 42 43 var found *grants.Grant 44 for _, v := range grantList.Grants { 45 if v.GrantID == createGrant.GrantID { 46 found = &v 47 break 48 } 49 } 50 if found == nil { 51 t.Fatal("created grant wasn't found by ID") 52 } 53 th.AssertEquals(t, createOpts.Name, found.Name) 54 th.AssertEquals(t, len(createOpts.Operations), len(found.Operations)) 55 }