github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/instanceactions/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/instanceactions" 10 th "github.com/gophercloud/gophercloud/testhelper" 11 "github.com/gophercloud/gophercloud/testhelper/client" 12 ) 13 14 // ListExpected represents an expected repsonse from a List request. 15 var ListExpected = []instanceactions.InstanceAction{ 16 { 17 Action: "stop", 18 InstanceUUID: "fcd19ef2-b593-40b1-90a5-fc31063fa95c", 19 Message: "", 20 ProjectID: "6f70656e737461636b20342065766572", 21 RequestID: "req-f8a59f03-76dc-412f-92c2-21f8612be728", 22 StartTime: time.Date(2018, 04, 25, 1, 26, 29, 000000, time.UTC), 23 UserID: "admin", 24 }, 25 { 26 Action: "create", 27 InstanceUUID: "fcd19ef2-b593-40b1-90a5-fc31063fa95c", 28 Message: "test", 29 ProjectID: "6f70656e737461636b20342065766572", 30 RequestID: "req-50189019-626d-47fb-b944-b8342af09679", 31 StartTime: time.Date(2018, 04, 25, 1, 26, 25, 000000, time.UTC), 32 UserID: "admin", 33 }, 34 } 35 36 // HandleInstanceActionListSuccessfully sets up the test server to respond to a ListAddresses request. 37 func HandleInstanceActionListSuccessfully(t *testing.T) { 38 th.Mux.HandleFunc("/servers/asdfasdfasdf/os-instance-actions", func(w http.ResponseWriter, r *http.Request) { 39 th.TestMethod(t, r, "GET") 40 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 41 42 w.Header().Add("Content-Type", "application/json") 43 fmt.Fprintf(w, `{ 44 "instanceActions": [ 45 { 46 "action": "stop", 47 "instance_uuid": "fcd19ef2-b593-40b1-90a5-fc31063fa95c", 48 "message": null, 49 "project_id": "6f70656e737461636b20342065766572", 50 "request_id": "req-f8a59f03-76dc-412f-92c2-21f8612be728", 51 "start_time": "2018-04-25T01:26:29.000000", 52 "user_id": "admin" 53 }, 54 { 55 "action": "create", 56 "instance_uuid": "fcd19ef2-b593-40b1-90a5-fc31063fa95c", 57 "message": "test", 58 "project_id": "6f70656e737461636b20342065766572", 59 "request_id": "req-50189019-626d-47fb-b944-b8342af09679", 60 "start_time": "2018-04-25T01:26:25.000000", 61 "user_id": "admin" 62 } 63 ] 64 }`) 65 }) 66 } 67 68 var ( 69 expectedUpdateAt = time.Date(2018, 04, 25, 1, 26, 36, 0, time.UTC) 70 expectedEventHost = "compute" 71 expectedEventHostID = "2091634baaccdc4c5a1d57069c833e402921df696b7f970791b12ec6" 72 expectedEvents = []instanceactions.Event{{ 73 Event: "compute_stop_instance", 74 Host: &expectedEventHost, 75 HostID: &expectedEventHostID, 76 Result: "Success", 77 StartTime: time.Date(2018, 04, 25, 1, 26, 36, 0, time.UTC), 78 FinishTime: time.Date(2018, 04, 25, 1, 26, 36, 0, time.UTC), 79 Traceback: "", 80 }} 81 ) 82 83 // GetExpected represents an expected repsonse from a Get request. 84 var GetExpected = instanceactions.InstanceActionDetail{ 85 Action: "stop", 86 InstanceUUID: "4bf3473b-d550-4b65-9409-292d44ab14a2", 87 Message: "", 88 ProjectID: "6f70656e737461636b20342065766572", 89 RequestID: "req-0d819d5c-1527-4669-bdf0-ffad31b5105b", 90 StartTime: time.Date(2018, 04, 25, 1, 26, 36, 0, time.UTC), 91 UpdatedAt: &expectedUpdateAt, 92 UserID: "admin", 93 Events: &expectedEvents, 94 } 95 96 // HandleInstanceActionGetSuccessfully sets up the test server to respond to a Get request. 97 func HandleInstanceActionGetSuccessfully(t *testing.T) { 98 th.Mux.HandleFunc("/servers/asdfasdfasdf/os-instance-actions/okzeorkmkfs", func(w http.ResponseWriter, r *http.Request) { 99 th.TestMethod(t, r, "GET") 100 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 101 102 w.Header().Add("Content-Type", "application/json") 103 fmt.Fprintf(w, `{ 104 "instanceAction": 105 { 106 "action": "stop", 107 "events": [ 108 { 109 "event": "compute_stop_instance", 110 "finish_time": "2018-04-25T01:26:36.00000", 111 "host": "compute", 112 "hostId": "2091634baaccdc4c5a1d57069c833e402921df696b7f970791b12ec6", 113 "result": "Success", 114 "start_time": "2018-04-25T01:26:36.00000", 115 "traceback": null 116 } 117 ], 118 "instance_uuid": "4bf3473b-d550-4b65-9409-292d44ab14a2", 119 "message": null, 120 "project_id": "6f70656e737461636b20342065766572", 121 "request_id": "req-0d819d5c-1527-4669-bdf0-ffad31b5105b", 122 "start_time": "2018-04-25T01:26:36.00000", 123 "updated_at": "2018-04-25T01:26:36.00000", 124 "user_id": "admin" 125 } 126 }`) 127 }) 128 }