github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/networking/v1/bandwidths_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/tools"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v1/bandwidths"
     9  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    10  )
    11  
    12  func TestBandwidthsList(t *testing.T) {
    13  	client, err := clients.NewNetworkV1Client()
    14  	th.AssertNoErr(t, err)
    15  
    16  	// Create eip/bandwidth
    17  	eip := CreateEip(t, client, 1)
    18  	defer DeleteEip(t, client, eip.ID)
    19  
    20  	// Query a bandwidth
    21  	existingBandwidths, err := bandwidths.List(client, bandwidths.ListOpts{
    22  		ShareType: "PER",
    23  	}).Extract()
    24  	th.AssertNoErr(t, err)
    25  
    26  	for _, b := range existingBandwidths {
    27  		if b.ID == eip.BandwidthID {
    28  			t.Logf("Bandwith with ID %s is in bandwidth list", b.ID)
    29  			return
    30  		}
    31  	}
    32  	t.Errorf("Failed to find created bandwidth")
    33  }
    34  
    35  func TestBandwidthsLifecycle(t *testing.T) {
    36  	client, err := clients.NewNetworkV1Client()
    37  	th.AssertNoErr(t, err)
    38  
    39  	bandwidthSize := 100
    40  	// Create eip/bandwidth
    41  	eip := CreateEip(t, client, bandwidthSize)
    42  	defer DeleteEip(t, client, eip.ID)
    43  
    44  	tools.PrintResource(t, eip)
    45  
    46  	// Update a bandwidth
    47  	newBandWidthSize := bandwidthSize / 2
    48  	updateOpts := bandwidths.UpdateOpts{
    49  		Size: newBandWidthSize,
    50  	}
    51  	updatedBand, err := bandwidths.Update(client, eip.BandwidthID, updateOpts).Extract()
    52  	th.AssertNoErr(t, err)
    53  
    54  	// Query a bandwidth
    55  	newBandWidth, err := bandwidths.Get(client, updatedBand.ID).Extract()
    56  	th.AssertNoErr(t, err)
    57  
    58  	tools.PrintResource(t, newBandWidth)
    59  }