github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/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/blockstorage/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 "status": "enabled", 19 "binary": "cinder-scheduler", 20 "zone": "nova", 21 "state": "up", 22 "updated_at": "2017-06-29T05:50:35.000000", 23 "host": "devstack", 24 "disabled_reason": null 25 }, 26 { 27 "status": "enabled", 28 "binary": "cinder-backup", 29 "zone": "nova", 30 "state": "up", 31 "updated_at": "2017-06-29T05:50:42.000000", 32 "host": "devstack", 33 "disabled_reason": null 34 }, 35 { 36 "status": "enabled", 37 "binary": "cinder-volume", 38 "zone": "nova", 39 "frozen": false, 40 "state": "up", 41 "updated_at": "2017-06-29T05:50:39.000000", 42 "cluster": null, 43 "host": "devstack@lvmdriver-1", 44 "replication_status": "disabled", 45 "active_backend_id": null, 46 "disabled_reason": null 47 }] 48 } 49 ` 50 51 // First service from the ServiceListBody 52 var FirstFakeService = services.Service{ 53 Binary: "cinder-scheduler", 54 DisabledReason: "", 55 Host: "devstack", 56 State: "up", 57 Status: "enabled", 58 UpdatedAt: time.Date(2017, 6, 29, 5, 50, 35, 0, time.UTC), 59 Zone: "nova", 60 } 61 62 // Second service from the ServiceListBody 63 var SecondFakeService = services.Service{ 64 Binary: "cinder-backup", 65 DisabledReason: "", 66 Host: "devstack", 67 State: "up", 68 Status: "enabled", 69 UpdatedAt: time.Date(2017, 6, 29, 5, 50, 42, 0, time.UTC), 70 Zone: "nova", 71 } 72 73 // Third service from the ServiceListBody 74 var ThirdFakeService = services.Service{ 75 ActiveBackendID: "", 76 Binary: "cinder-volume", 77 Cluster: "", 78 DisabledReason: "", 79 Frozen: false, 80 Host: "devstack@lvmdriver-1", 81 ReplicationStatus: "disabled", 82 State: "up", 83 Status: "enabled", 84 UpdatedAt: time.Date(2017, 6, 29, 5, 50, 39, 0, time.UTC), 85 Zone: "nova", 86 } 87 88 // HandleListSuccessfully configures the test server to respond to a List request. 89 func HandleListSuccessfully(t *testing.T) { 90 th.Mux.HandleFunc("/os-services", func(w http.ResponseWriter, r *http.Request) { 91 th.TestMethod(t, r, "GET") 92 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 93 94 w.Header().Add("Content-Type", "application/json") 95 fmt.Fprintf(w, ServiceListBody) 96 }) 97 }