github.com/gophercloud/gophercloud@v1.11.0/openstack/cdn/v1/flavors/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/openstack/cdn/v1/flavors" 8 "github.com/gophercloud/gophercloud/pagination" 9 th "github.com/gophercloud/gophercloud/testhelper" 10 fake "github.com/gophercloud/gophercloud/testhelper/client" 11 ) 12 13 func TestList(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 17 HandleListCDNFlavorsSuccessfully(t) 18 19 count := 0 20 21 err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { 22 count++ 23 actual, err := flavors.ExtractFlavors(page) 24 if err != nil { 25 t.Errorf("Failed to extract flavors: %v", err) 26 return false, err 27 } 28 29 expected := []flavors.Flavor{ 30 { 31 ID: "europe", 32 Providers: []flavors.Provider{ 33 { 34 Provider: "Fastly", 35 Links: []gophercloud.Link{ 36 { 37 Href: "http://www.fastly.com", 38 Rel: "provider_url", 39 }, 40 }, 41 }, 42 }, 43 Links: []gophercloud.Link{ 44 { 45 Href: "https://www.poppycdn.io/v1.0/flavors/europe", 46 Rel: "self", 47 }, 48 }, 49 }, 50 } 51 52 th.CheckDeepEquals(t, expected, actual) 53 54 return true, nil 55 }) 56 th.AssertNoErr(t, err) 57 th.CheckEquals(t, 1, count) 58 } 59 60 func TestGet(t *testing.T) { 61 th.SetupHTTP() 62 defer th.TeardownHTTP() 63 64 HandleGetCDNFlavorSuccessfully(t) 65 66 expected := &flavors.Flavor{ 67 ID: "asia", 68 Providers: []flavors.Provider{ 69 { 70 Provider: "ChinaCache", 71 Links: []gophercloud.Link{ 72 { 73 Href: "http://www.chinacache.com", 74 Rel: "provider_url", 75 }, 76 }, 77 }, 78 }, 79 Links: []gophercloud.Link{ 80 { 81 Href: "https://www.poppycdn.io/v1.0/flavors/asia", 82 Rel: "self", 83 }, 84 }, 85 } 86 87 actual, err := flavors.Get(fake.ServiceClient(), "asia").Extract() 88 th.AssertNoErr(t, err) 89 th.AssertDeepEquals(t, expected, actual) 90 }