Skip to content

Commit 5f4d249

Browse files
author
Samuel Allan
committed
Add unit test
1 parent c0c4736 commit 5f4d249

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

openstack/compute/v2/hypervisors/testing/fixtures_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,36 @@ const HypervisorGetEmptyCPUInfoBody = `
346346
}
347347
`
348348

349+
// HypervisorAfterV287ResponseBody represents a raw hypervisor GET result with
350+
// missing cpu_info, free_disk_gb, local_gb as seen after v2.87
351+
const HypervisorAfterV287ResponseBody = `
352+
{
353+
"hypervisor":{
354+
"current_workload":0,
355+
"status":"enabled",
356+
"state":"up",
357+
"disk_available_least":0,
358+
"host_ip":"1.1.1.1",
359+
"free_ram_mb":7680,
360+
"hypervisor_hostname":"fake-mini",
361+
"hypervisor_type":"fake",
362+
"hypervisor_version":2002000,
363+
"id":"c48f6247-abe4-4a24-824e-ea39e108874f",
364+
"local_gb_used":0,
365+
"memory_mb":8192,
366+
"memory_mb_used":512,
367+
"running_vms":0,
368+
"service":{
369+
"host":"e6a37ee802d74863ab8b91ade8f12a67",
370+
"id":"9c2566e7-7a54-4777-a1ae-c2662f0c407c",
371+
"disabled_reason":null
372+
},
373+
"vcpus":1,
374+
"vcpus_used":0
375+
}
376+
}
377+
`
378+
349379
// HypervisorUptimeBody represents a raw hypervisor uptime request result with
350380
// Pike+ release.
351381
const HypervisorUptimeBody = `
@@ -492,6 +522,7 @@ var (
492522
}
493523

494524
HypervisorEmptyCPUInfo = hypervisors.Hypervisor{
525+
CPUInfo: hypervisors.CPUInfo{},
495526
CurrentWorkload: 0,
496527
Status: "enabled",
497528
State: "up",
@@ -517,6 +548,33 @@ var (
517548
VCPUsUsed: 0,
518549
}
519550

551+
HypervisorAfterV287Response = hypervisors.Hypervisor{
552+
CPUInfo: hypervisors.CPUInfo{},
553+
CurrentWorkload: 0,
554+
Status: "enabled",
555+
State: "up",
556+
DiskAvailableLeast: 0,
557+
HostIP: "1.1.1.1",
558+
FreeDiskGB: 0,
559+
FreeRamMB: 7680,
560+
HypervisorHostname: "fake-mini",
561+
HypervisorType: "fake",
562+
HypervisorVersion: 2002000,
563+
ID: "c48f6247-abe4-4a24-824e-ea39e108874f",
564+
LocalGB: 0,
565+
LocalGBUsed: 0,
566+
MemoryMB: 8192,
567+
MemoryMBUsed: 512,
568+
RunningVMs: 0,
569+
Service: hypervisors.Service{
570+
Host: "e6a37ee802d74863ab8b91ade8f12a67",
571+
ID: "9c2566e7-7a54-4777-a1ae-c2662f0c407c",
572+
DisabledReason: "",
573+
},
574+
VCPUs: 1,
575+
VCPUsUsed: 0,
576+
}
577+
520578
HypervisorsStatisticsExpected = hypervisors.Statistics{
521579
Count: 1,
522580
CurrentWorkload: 0,
@@ -604,6 +662,16 @@ func HandleHypervisorGetEmptyCPUInfoSuccessfully(t *testing.T) {
604662
})
605663
}
606664

665+
func HandleHypervisorAfterV287ResponseSuccessfully(t *testing.T) {
666+
testhelper.Mux.HandleFunc("/os-hypervisors/"+HypervisorFake.ID, func(w http.ResponseWriter, r *http.Request) {
667+
testhelper.TestMethod(t, r, "GET")
668+
testhelper.TestHeader(t, r, "X-Auth-Token", client.TokenID)
669+
670+
w.Header().Add("Content-Type", "application/json")
671+
fmt.Fprintf(w, HypervisorAfterV287ResponseBody)
672+
})
673+
}
674+
607675
func HandleHypervisorUptimeSuccessfully(t *testing.T) {
608676
testhelper.Mux.HandleFunc("/os-hypervisors/"+HypervisorFake.ID+"/uptime", func(w http.ResponseWriter, r *http.Request) {
609677
testhelper.TestMethod(t, r, "GET")

openstack/compute/v2/hypervisors/testing/requests_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ func TestGetHypervisorEmptyCPUInfo(t *testing.T) {
148148
testhelper.CheckDeepEquals(t, &expected, actual)
149149
}
150150

151+
func TestGetHypervisorAfterV287Response(t *testing.T) {
152+
testhelper.SetupHTTP()
153+
defer testhelper.TeardownHTTP()
154+
HandleHypervisorAfterV287ResponseSuccessfully(t)
155+
156+
expected := HypervisorAfterV287Response
157+
158+
actual, err := hypervisors.Get(context.TODO(), client.ServiceClient(), expected.ID).Extract()
159+
testhelper.AssertNoErr(t, err)
160+
testhelper.CheckDeepEquals(t, &expected, actual)
161+
}
162+
151163
func TestHypervisorsUptime(t *testing.T) {
152164
testhelper.SetupHTTP()
153165
defer testhelper.TeardownHTTP()

0 commit comments

Comments
 (0)