github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/apiversions/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/vnpaycloud-console/gophercloud/v2/openstack/compute/apiversions" 8 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 9 "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 10 ) 11 12 func TestListAPIVersions(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 16 MockListResponse(t) 17 18 allVersions, err := apiversions.List(client.ServiceClient()).AllPages(context.TODO()) 19 th.AssertNoErr(t, err) 20 21 actual, err := apiversions.ExtractAPIVersions(allVersions) 22 th.AssertNoErr(t, err) 23 24 th.AssertDeepEquals(t, NovaAllAPIVersionResults, actual) 25 } 26 27 func TestGetAPIVersion(t *testing.T) { 28 th.SetupHTTP() 29 defer th.TeardownHTTP() 30 31 MockGetResponse(t) 32 33 actual, err := apiversions.Get(context.TODO(), client.ServiceClient(), "v2.1").Extract() 34 th.AssertNoErr(t, err) 35 36 th.AssertDeepEquals(t, NovaAPIVersion21Result, *actual) 37 } 38 39 func TestGetMultipleAPIVersion(t *testing.T) { 40 th.SetupHTTP() 41 defer th.TeardownHTTP() 42 43 MockGetMultipleResponses(t) 44 45 _, err := apiversions.Get(context.TODO(), client.ServiceClient(), "v3").Extract() 46 th.AssertEquals(t, err.Error(), "Unable to find requested API version") 47 }