github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/elb/v3/certificates_test.go (about)

     1  package v3
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/elb/v3/certificates"
     9  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    10  )
    11  
    12  func TestCertificateList(t *testing.T) {
    13  	client, err := clients.NewElbV3Client()
    14  	th.AssertNoErr(t, err)
    15  
    16  	listOpts := certificates.ListOpts{}
    17  	certificatePages, err := certificates.List(client, listOpts).AllPages()
    18  	th.AssertNoErr(t, err)
    19  
    20  	certificateList, err := certificates.ExtractCertificates(certificatePages)
    21  	th.AssertNoErr(t, err)
    22  
    23  	for _, cert := range certificateList {
    24  		tools.PrintResource(t, cert)
    25  	}
    26  }
    27  
    28  func TestCertificateLifecycle(t *testing.T) {
    29  	client, err := clients.NewElbV3Client()
    30  	th.AssertNoErr(t, err)
    31  
    32  	certificateID := createCertificate(t, client)
    33  	defer deleteCertificate(t, client, certificateID)
    34  
    35  	t.Logf("Attempting to update ELBv3 certificate: %s", certificateID)
    36  	certName := tools.RandomString("update-cert-", 3)
    37  	emptyDescription := ""
    38  	updateOpts := certificates.UpdateOpts{
    39  		Name:        certName,
    40  		Description: &emptyDescription,
    41  	}
    42  
    43  	_, err = certificates.Update(client, certificateID, updateOpts).Extract()
    44  	th.AssertNoErr(t, err)
    45  	t.Logf("Updated ELBv3 certificate: %s", certificateID)
    46  
    47  	newCertificate, err := certificates.Get(client, certificateID).Extract()
    48  	th.AssertNoErr(t, err)
    49  	th.AssertEquals(t, updateOpts.Name, newCertificate.Name)
    50  	th.AssertEquals(t, emptyDescription, newCertificate.Description)
    51  }