github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/autoscaling/v1/configurations_test.go (about)

     1  package v1
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack/autoscaling"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
     9  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/autoscaling/v1/configurations"
    10  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    11  )
    12  
    13  func TestConfigurationsList(t *testing.T) {
    14  	client, err := clients.NewAutoscalingV1Client()
    15  	th.AssertNoErr(t, err)
    16  
    17  	listOpts := configurations.ListOpts{}
    18  
    19  	configs, err := configurations.List(client, listOpts)
    20  	th.AssertNoErr(t, err)
    21  
    22  	for _, config := range configs.ScalingConfigurations {
    23  		tools.PrintResource(t, config)
    24  	}
    25  }
    26  
    27  func TestConfigurationsLifecycle(t *testing.T) {
    28  	client, err := clients.NewAutoscalingV1Client()
    29  	th.AssertNoErr(t, err)
    30  
    31  	asCreateName := tools.RandomString("as-create-", 3)
    32  	keyPairName := clients.EnvOS.GetEnv("KEYPAIR_NAME")
    33  	imageID := clients.EnvOS.GetEnv("IMAGE_ID")
    34  	if keyPairName == "" || imageID == "" {
    35  		t.Skip("OS_KEYPAIR_NAME or OS_IMAGE_ID env vars is missing but AS Configuration test requires")
    36  	}
    37  
    38  	configID := autoscaling.CreateASConfig(t, client, asCreateName, imageID, keyPairName)
    39  
    40  	t.Cleanup(func() {
    41  		autoscaling.DeleteASConfig(t, client, configID)
    42  	})
    43  
    44  	config, err := configurations.Get(client, configID)
    45  	th.AssertNoErr(t, err)
    46  	tools.PrintResource(t, config)
    47  	th.AssertEquals(t, 1, len(config.InstanceConfig.SecurityGroups))
    48  }