github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/smn/v2/helpers.go (about)

     1  package v2
     2  
     3  import (
     4  	"testing"
     5  
     6  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
     9  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
    10  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/smn/v2/topics"
    11  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    12  )
    13  
    14  func createTopic(t *testing.T, client *golangsdk.ServiceClient) string {
    15  	t.Logf("Attempting to create SMN topic")
    16  	topicName := tools.RandomString("topic-", 3)
    17  	opts := topics.CreateOps{
    18  		Name: topicName,
    19  	}
    20  	topic, err := topics.Create(client, opts).Extract()
    21  	th.AssertNoErr(t, err)
    22  	t.Logf("Created SMN topic: %s", topic.TopicUrn)
    23  
    24  	tagsClient, err := clients.NewSmnV2TagsClient()
    25  	th.AssertNoErr(t, err)
    26  
    27  	tagsClient.MoreHeaders = map[string]string{
    28  		"X-SMN-RESOURCEID-TYPE": "name",
    29  	}
    30  	tagOpts := []tags.ResourceTag{
    31  		{
    32  			Key:   "muh",
    33  			Value: "lala",
    34  		},
    35  		{
    36  			Key:   "kuh",
    37  			Value: "lala",
    38  		},
    39  	}
    40  	t.Logf("Attempting to create SMN topic tags: %s", tagOpts)
    41  	err = tags.Create(tagsClient, "smn_topic", topicName, tagOpts).ExtractErr()
    42  	th.AssertNoErr(t, err)
    43  
    44  	listTags, err := tags.Get(tagsClient, "smn_topic", topicName).Extract()
    45  	th.AssertNoErr(t, err)
    46  	if len(listTags) < 1 {
    47  		t.Fatal("empty SMN topic tags list")
    48  	}
    49  	t.Logf("SMN topic tags: %s", listTags)
    50  
    51  	tagOptsUpdate := []tags.ResourceTag{
    52  		{
    53  			Key:   "kuh",
    54  			Value: "lala",
    55  		},
    56  	}
    57  
    58  	t.Logf("Attempting to delete SMN topic tag")
    59  	err = tags.Delete(tagsClient, "smn_topic", topicName, tagOptsUpdate).ExtractErr()
    60  	th.AssertNoErr(t, err)
    61  
    62  	return topic.TopicUrn
    63  }
    64  
    65  func deleteTopic(t *testing.T, client *golangsdk.ServiceClient, topicURN string) {
    66  	t.Logf("Attempting to delete SMN topic: %s", topicURN)
    67  	err := topics.Delete(client, topicURN).ExtractErr()
    68  	th.AssertNoErr(t, err)
    69  	t.Logf("Deleted SMN topic: %s", topicURN)
    70  }