github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/bms/v1/flavors/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/chnsz/golangsdk" 9 "github.com/chnsz/golangsdk/openstack/bms/v1/flavors" 10 th "github.com/chnsz/golangsdk/testhelper" 11 fake "github.com/chnsz/golangsdk/testhelper/client" 12 ) 13 14 func TestListFlavor(t *testing.T) { 15 th.SetupHTTP() 16 defer th.TeardownHTTP() 17 18 th.Mux.HandleFunc("/baremetalservers/flavors", 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 "id": "physical.d2.large", 30 "name": "physical.d2.large", 31 "vcpus": "48", 32 "ram": 196608, 33 "disk": "120600", 34 "swap": "", 35 "links": [ 36 { 37 "rel": "self", 38 "href": "https://compute-ext.region.cn-north-1.hwclouds.com/v1.0/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.d2.large", 39 "type": null 40 }, 41 { 42 "rel": "bookmark", 43 "href": "https://compute-ext.region.cn-north-1.hwclouds.com/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.d2.large", 44 "type": null 45 } 46 ], 47 "OS-FLV-EXT-DATA:ephemeral": 0, 48 "rxtx_factor": 1.0, 49 "OS-FLV-DISABLED:disabled": false, 50 "rxtx_quota": null, 51 "rxtx_cap": null, 52 "os-flavor-access:is_public": true, 53 "os_extra_specs": { 54 "capabilities:cpu_arch": "x86_64", 55 "cond:operation:az": "cn-north-1a(sellout),cn-north-1b(sellout)", 56 "capabilities:hypervisor_type": "ironic", 57 "baremetal:__support_evs": "false", 58 "baremetal:extBootType": "LocalDisk", 59 "capabilities:board_type": "d2l", 60 "cond:operation:status": "abandon", 61 "baremetal:net_num": "2", 62 "baremetal:netcard_detail": "2 x 2*10GE", 63 "baremetal:disk_detail": "2*600G SAS System Disk RAID 1+ 12*10T SATA", 64 "baremetal:cpu_detail": "Intel Xeon Gold 5118 V5 (2*12Core 2.30GHz)", 65 "resource_type": "ironic", 66 "baremetal:memory_detail": "192GB DDR4" 67 } 68 }, 69 { 70 "id": "physical.io2.xlarge", 71 "name": "physical.io2.xlarge", 72 "vcpus": "88", 73 "ram": 393216, 74 "disk": "8800", 75 "swap": "", 76 "links": [ 77 { 78 "rel": "self", 79 "href": "https://compute-ext.region.cn-north-1.hwclouds.com/v1.0/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.io2.xlarge", 80 "type": null 81 }, 82 { 83 "rel": "bookmark", 84 "href": "https://compute-ext.region.cn-north-1.hwclouds.com/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.io2.xlarge", 85 "type": null 86 } 87 ], 88 "OS-FLV-EXT-DATA:ephemeral": 0, 89 "rxtx_factor": 1.0, 90 "OS-FLV-DISABLED:disabled": false, 91 "rxtx_quota": null, 92 "rxtx_cap": null, 93 "os-flavor-access:is_public": true, 94 "os_extra_specs": { 95 "capabilities:cpu_arch": "x86_64", 96 "cond:operation:az": "cn-north-1a(normal),cn-north-1b(normal)", 97 "capabilities:hypervisor_type": "ironic", 98 "baremetal:__support_evs": "false", 99 "baremetal:extBootType": "LocalDisk", 100 "capabilities:board_type": "io2xl", 101 "cond:operation:status": "normal", 102 "baremetal:net_num": "2", 103 "baremetal:netcard_detail": "2 x 2*10GE", 104 "baremetal:disk_detail": "2*800G SSD Raid 1 + 10* 800G SSD", 105 "baremetal:cpu_detail": "Intel Xeon Gold 6161 V5(2*22core*2.2 GHz)", 106 "resource_type": "ironic", 107 "baremetal:memory_detail": "12*32GB DDR4" 108 } 109 } 110 ] 111 } 112 `) 113 }) 114 115 actual, err := flavors.List(fake.ServiceClient(), flavors.ListOpts{}).Extract() 116 if err != nil { 117 t.Errorf("Failed to extract flavors: %v", err) 118 } 119 120 expected := []flavors.Flavor{ 121 { 122 ID: "physical.d2.large", 123 Name: "physical.d2.large", 124 VCPUs: "48", 125 RAM: 196608, 126 Disk: "120600", 127 IsPublic: true, 128 Disabled: false, 129 RxTxFactor: 1.0, 130 Ephemeral: 0, 131 Links: []golangsdk.Link{ 132 { 133 Href: "https://compute-ext.region.cn-north-1.hwclouds.com/v1.0/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.d2.large", 134 Rel: "self", 135 }, 136 { 137 Href: "https://compute-ext.region.cn-north-1.hwclouds.com/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.d2.large", 138 Rel: "bookmark", 139 }, 140 }, 141 OsExtraSpecs: flavors.OsExtraSpecs{ 142 Type: "ironic", 143 CPUArch: "x86_64", 144 FlavorType: "d2l", 145 HypervisorType: "ironic", 146 SupportEvs: "false", 147 BootFrom: "LocalDisk", 148 NetNum: "2", 149 CPUDetail: "Intel Xeon Gold 5118 V5 (2*12Core 2.30GHz)", 150 MemoryDetail: "192GB DDR4", 151 DiskDetail: "2*600G SAS System Disk RAID 1+ 12*10T SATA", 152 NetcardDetail: "2 x 2*10GE", 153 OperationStatus: "abandon", 154 OperationAZ: "cn-north-1a(sellout),cn-north-1b(sellout)", 155 }, 156 }, 157 { 158 ID: "physical.io2.xlarge", 159 Name: "physical.io2.xlarge", 160 VCPUs: "88", 161 RAM: 393216, 162 Disk: "8800", 163 IsPublic: true, 164 Disabled: false, 165 RxTxFactor: 1.0, 166 Ephemeral: 0, 167 Links: []golangsdk.Link{ 168 { 169 Href: "https://compute-ext.region.cn-north-1.hwclouds.com/v1.0/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.io2.xlarge", 170 Rel: "self", 171 }, 172 { 173 Href: "https://compute-ext.region.cn-north-1.hwclouds.com/0970dd7a1300f5672ff2c003c60ae115/flavors/physical.io2.xlarge", 174 Rel: "bookmark", 175 }, 176 }, 177 OsExtraSpecs: flavors.OsExtraSpecs{ 178 Type: "ironic", 179 CPUArch: "x86_64", 180 FlavorType: "io2xl", 181 HypervisorType: "ironic", 182 SupportEvs: "false", 183 BootFrom: "LocalDisk", 184 NetNum: "2", 185 CPUDetail: "Intel Xeon Gold 6161 V5(2*22core*2.2 GHz)", 186 MemoryDetail: "12*32GB DDR4", 187 DiskDetail: "2*800G SSD Raid 1 + 10* 800G SSD", 188 NetcardDetail: "2 x 2*10GE", 189 OperationStatus: "normal", 190 OperationAZ: "cn-north-1a(normal),cn-north-1b(normal)", 191 }, 192 }, 193 } 194 195 th.AssertDeepEquals(t, expected, actual) 196 }