github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/loadbalancer/v2/amphorae/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/loadbalancer/v2/amphorae"
     8  	fake "github.com/vnpaycloud-console/gophercloud/v2/openstack/loadbalancer/v2/testhelper"
     9  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
    10  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    11  )
    12  
    13  func TestListAmphorae(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	HandleAmphoraListSuccessfully(t)
    17  
    18  	pages := 0
    19  	err := amphorae.List(fake.ServiceClient(), amphorae.ListOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    20  		pages++
    21  
    22  		actual, err := amphorae.ExtractAmphorae(page)
    23  		if err != nil {
    24  			return false, err
    25  		}
    26  
    27  		if len(actual) != 2 {
    28  			t.Fatalf("Expected 2 amphorae, got %d", len(actual))
    29  		}
    30  
    31  		return true, nil
    32  	})
    33  
    34  	th.AssertNoErr(t, err)
    35  
    36  	if pages != 1 {
    37  		t.Errorf("Expected 1 page, saw %d", pages)
    38  	}
    39  }
    40  
    41  func TestListAllAmphorae(t *testing.T) {
    42  	th.SetupHTTP()
    43  	defer th.TeardownHTTP()
    44  	HandleAmphoraListSuccessfully(t)
    45  
    46  	allPages, err := amphorae.List(fake.ServiceClient(), amphorae.ListOpts{}).AllPages(context.TODO())
    47  	th.AssertNoErr(t, err)
    48  	actual, err := amphorae.ExtractAmphorae(allPages)
    49  	th.AssertNoErr(t, err)
    50  	th.AssertEquals(t, 2, len(actual))
    51  	th.AssertDeepEquals(t, ExpectedAmphoraeSlice, actual)
    52  }
    53  
    54  func TestGetAmphora(t *testing.T) {
    55  	th.SetupHTTP()
    56  	defer th.TeardownHTTP()
    57  	HandleAmphoraGetSuccessfully(t)
    58  
    59  	client := fake.ServiceClient()
    60  	actual, err := amphorae.Get(context.TODO(), client, "45f40289-0551-483a-b089-47214bc2a8a4").Extract()
    61  	if err != nil {
    62  		t.Fatalf("Unexpected Get error: %v", err)
    63  	}
    64  
    65  	th.CheckDeepEquals(t, FirstAmphora, *actual)
    66  }
    67  
    68  func TestFailoverAmphora(t *testing.T) {
    69  	th.SetupHTTP()
    70  	defer th.TeardownHTTP()
    71  	HandleAmphoraFailoverSuccessfully(t)
    72  
    73  	res := amphorae.Failover(context.TODO(), fake.ServiceClient(), "36e08a3e-a78f-4b40-a229-1e7e23eee1ab")
    74  	th.AssertNoErr(t, res.Err)
    75  }