github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/smn/v2/topicattributes_test.go (about) 1 package v2 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 8 "github.com/opentelekomcloud/gophertelekomcloud/openstack/smn/v2/topicattributes" 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 ) 11 12 func TestTopicAttributeWorkflow(t *testing.T) { 13 client, err := clients.NewSmnV2Client() 14 th.AssertNoErr(t, err) 15 16 topic := createTopic(t, client) 17 defer deleteTopic(t, client, topic) 18 19 examplePolicy := fmt.Sprintf(policyTemplate, topic) 20 opts := topicattributes.UpdateOpts{ 21 Value: examplePolicy, 22 } 23 err = topicattributes.Update(client, topic, attribute, opts).ExtractErr() 24 th.AssertNoErr(t, err) 25 26 listOpts := topicattributes.ListOpts{Name: attribute} 27 attributes, err := topicattributes.List(client, topic, listOpts).Extract() 28 th.AssertNoErr(t, err) 29 th.AssertEquals(t, examplePolicy, attributes[attribute]) 30 31 err = topicattributes.Delete(client, topic, attribute).ExtractErr() 32 th.AssertNoErr(t, err) 33 } 34 35 const ( 36 attribute = "access_policy" 37 policyTemplate = ` 38 { 39 "Version": "2016-09-07", 40 "Id": "__default_policy_ID", 41 "Statement": [ 42 { 43 "Sid": "__service_pub_0", 44 "Effect": "Allow", 45 "Principal": { 46 "Service": [ 47 "OBS" 48 ] 49 }, 50 "Action": [ 51 "SMN:Publish", 52 "SMN:QueryTopicDetail" 53 ], 54 "Resource": "%s" 55 } 56 ] 57 } 58 ` 59 )