github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/bms/v2/flavors/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk" 9 "github.com/huaweicloud/golangsdk/openstack/bms/v2/flavors" 10 th "github.com/huaweicloud/golangsdk/testhelper" 11 fake "github.com/huaweicloud/golangsdk/testhelper/client" 12 ) 13 14 func TestListFlavor(t *testing.T) { 15 th.SetupHTTP() 16 defer th.TeardownHTTP() 17 18 th.Mux.HandleFunc("/flavors/detail", func(w http.ResponseWriter, r *http.Request) { 19 th.TestMethod(t, r, "GET") 20 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 21 22 w.Header().Add("Content-Type", "application/json") 23 w.WriteHeader(http.StatusOK) 24 25 fmt.Fprintf(w, ` 26 { 27 "flavors": [ 28 { 29 "name": "physical.h2.large", 30 "links": [ 31 { 32 "href": "https://compute.region.eu-de.otc-tsi.de/v2/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.h2.large", 33 "rel": "self" 34 }, 35 { 36 "href": "https://compute.region.eu-de.otc-tsi.de/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.h2.large", 37 "rel": "bookmark" 38 } 39 ], 40 "ram": 196608, 41 "OS-FLV-DISABLED:disabled": false, 42 "vcpus": 36, 43 "os-flavor-access:is_public": true, 44 "rxtx_factor": 1, 45 "OS-FLV-EXT-DATA:ephemeral": 0, 46 "disk": 0, 47 "id": "physical.h2.large" 48 }, 49 { 50 "name": "physical.m2.medium", 51 "links": [ 52 { 53 "href": "https://compute.region.eu-de.otc-tsi.de/v2/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.m2.medium", 54 "rel": "self" 55 }, 56 { 57 "href": "https://compute.region.eu-de.otc-tsi.de/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.m2.medium", 58 "rel": "bookmark" 59 } 60 ], 61 "ram": 2097152, 62 "OS-FLV-DISABLED:disabled": false, 63 "vcpus": 192, 64 "os-flavor-access:is_public": true, 65 "rxtx_factor": 1, 66 "OS-FLV-EXT-DATA:ephemeral": 0, 67 "disk": 17000, 68 "id": "physical.m2.medium" 69 } 70 ] 71 } 72 `) 73 }) 74 75 //count := 0 76 77 actual, err := flavors.List(fake.ServiceClient(), flavors.ListOpts{}) 78 if err != nil { 79 t.Errorf("Failed to extract flavors: %v", err) 80 } 81 82 expected := []flavors.Flavor{ 83 { 84 ID: "physical.h2.large", 85 RAM: 196608, 86 Disabled: false, 87 Name: "physical.h2.large", 88 VCPUs: 36, 89 IsPublic: true, 90 RxTxFactor: 1, 91 Ephemeral: 0, 92 Disk: 0, 93 Links: []golangsdk.Link{ 94 { 95 Href: "https://compute.region.eu-de.otc-tsi.de/v2/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.h2.large", 96 Rel: "self", 97 }, 98 { 99 Href: "https://compute.region.eu-de.otc-tsi.de/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.h2.large", 100 Rel: "bookmark", 101 }, 102 }, 103 }, 104 { 105 ID: "physical.m2.medium", 106 RAM: 2097152, 107 Disabled: false, 108 Name: "physical.m2.medium", 109 VCPUs: 192, 110 IsPublic: true, 111 RxTxFactor: 1, 112 Ephemeral: 0, 113 Disk: 17000, 114 Links: []golangsdk.Link{ 115 { 116 Href: "https://compute.region.eu-de.otc-tsi.de/v2/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.m2.medium", 117 Rel: "self", 118 }, 119 { 120 Href: "https://compute.region.eu-de.otc-tsi.de/91d687759aed45d28b5f6084bc2fa8ad/flavors/physical.m2.medium", 121 Rel: "bookmark", 122 }, 123 }, 124 }, 125 } 126 127 th.AssertDeepEquals(t, expected, actual) 128 }