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