github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/db/v1/flavors/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/openstack/db/v1/flavors" 8 "github.com/huaweicloud/golangsdk/pagination" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 fake "github.com/huaweicloud/golangsdk/testhelper/client" 11 ) 12 13 func TestListFlavors(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 HandleList(t) 17 18 pages := 0 19 err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { 20 pages++ 21 22 actual, err := flavors.ExtractFlavors(page) 23 if err != nil { 24 return false, err 25 } 26 27 expected := []flavors.Flavor{ 28 { 29 ID: 1, 30 Name: "m1.tiny", 31 RAM: 512, 32 Links: []golangsdk.Link{ 33 {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"}, 34 {Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"}, 35 }, 36 StrID: "1", 37 }, 38 { 39 ID: 2, 40 Name: "m1.small", 41 RAM: 1024, 42 Links: []golangsdk.Link{ 43 {Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"}, 44 {Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"}, 45 }, 46 StrID: "2", 47 }, 48 { 49 ID: 3, 50 Name: "m1.medium", 51 RAM: 2048, 52 Links: []golangsdk.Link{ 53 {Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"}, 54 {Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"}, 55 }, 56 StrID: "3", 57 }, 58 { 59 ID: 4, 60 Name: "m1.large", 61 RAM: 4096, 62 Links: []golangsdk.Link{ 63 {Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"}, 64 {Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"}, 65 }, 66 StrID: "4", 67 }, 68 { 69 ID: 0, 70 Name: "ds512M", 71 RAM: 512, 72 Links: []golangsdk.Link{ 73 {Href: "https://openstack.example.com/v1.0/1234/flavors/d1", Rel: "self"}, 74 {Href: "https://openstack.example.com/flavors/d1", Rel: "bookmark"}, 75 }, 76 StrID: "d1", 77 }, 78 } 79 80 th.AssertDeepEquals(t, expected, actual) 81 return true, nil 82 }) 83 84 th.AssertNoErr(t, err) 85 th.AssertEquals(t, 1, pages) 86 } 87 88 func TestGetFlavor(t *testing.T) { 89 th.SetupHTTP() 90 defer th.TeardownHTTP() 91 HandleGet(t) 92 93 actual, err := flavors.Get(fake.ServiceClient(), flavorID).Extract() 94 th.AssertNoErr(t, err) 95 96 expected := &flavors.Flavor{ 97 ID: 1, 98 Name: "m1.tiny", 99 RAM: 512, 100 Links: []golangsdk.Link{ 101 {Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"}, 102 }, 103 StrID: "1", 104 } 105 106 th.AssertDeepEquals(t, expected, actual) 107 }