github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/services/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/services" 10 th "github.com/huaweicloud/golangsdk/testhelper" 11 "github.com/huaweicloud/golangsdk/testhelper/client" 12 ) 13 14 // ServiceListBody is sample response to the List call 15 const ServiceListBody = ` 16 { 17 "services": [ 18 { 19 "id": 1, 20 "binary": "nova-scheduler", 21 "disabled_reason": "test1", 22 "host": "host1", 23 "state": "up", 24 "status": "disabled", 25 "updated_at": "2012-10-29T13:42:02.000000", 26 "forced_down": false, 27 "zone": "internal" 28 }, 29 { 30 "id": 2, 31 "binary": "nova-compute", 32 "disabled_reason": "test2", 33 "host": "host1", 34 "state": "up", 35 "status": "disabled", 36 "updated_at": "2012-10-29T13:42:05.000000", 37 "forced_down": false, 38 "zone": "nova" 39 }, 40 { 41 "id": 3, 42 "binary": "nova-scheduler", 43 "disabled_reason": null, 44 "host": "host2", 45 "state": "down", 46 "status": "enabled", 47 "updated_at": "2012-09-19T06:55:34.000000", 48 "forced_down": false, 49 "zone": "internal" 50 }, 51 { 52 "id": 4, 53 "binary": "nova-compute", 54 "disabled_reason": "test4", 55 "host": "host2", 56 "state": "down", 57 "status": "disabled", 58 "updated_at": "2012-09-18T08:03:38.000000", 59 "forced_down": false, 60 "zone": "nova" 61 } 62 ] 63 } 64 ` 65 66 // First service from the ServiceListBody 67 var FirstFakeService = services.Service{ 68 Binary: "nova-scheduler", 69 DisabledReason: "test1", 70 Host: "host1", 71 ID: 1, 72 State: "up", 73 Status: "disabled", 74 UpdatedAt: time.Date(2012, 10, 29, 13, 42, 2, 0, time.UTC), 75 Zone: "internal", 76 } 77 78 // Second service from the ServiceListBody 79 var SecondFakeService = services.Service{ 80 Binary: "nova-compute", 81 DisabledReason: "test2", 82 Host: "host1", 83 ID: 2, 84 State: "up", 85 Status: "disabled", 86 UpdatedAt: time.Date(2012, 10, 29, 13, 42, 5, 0, time.UTC), 87 Zone: "nova", 88 } 89 90 // Third service from the ServiceListBody 91 var ThirdFakeService = services.Service{ 92 Binary: "nova-scheduler", 93 DisabledReason: "", 94 Host: "host2", 95 ID: 3, 96 State: "down", 97 Status: "enabled", 98 UpdatedAt: time.Date(2012, 9, 19, 6, 55, 34, 0, time.UTC), 99 Zone: "internal", 100 } 101 102 // Fourth service from the ServiceListBody 103 var FourthFakeService = services.Service{ 104 Binary: "nova-compute", 105 DisabledReason: "test4", 106 Host: "host2", 107 ID: 4, 108 State: "down", 109 Status: "disabled", 110 UpdatedAt: time.Date(2012, 9, 18, 8, 3, 38, 0, time.UTC), 111 Zone: "nova", 112 } 113 114 // HandleListSuccessfully configures the test server to respond to a List request. 115 func HandleListSuccessfully(t *testing.T) { 116 th.Mux.HandleFunc("/os-services", func(w http.ResponseWriter, r *http.Request) { 117 th.TestMethod(t, r, "GET") 118 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 119 120 w.Header().Add("Content-Type", "application/json") 121 fmt.Fprintf(w, ServiceListBody) 122 }) 123 }