github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/evs/v1/jobs/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/evs/v1/jobs" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 "github.com/huaweicloud/golangsdk/testhelper/client" 11 ) 12 13 const expectedResponse = ` 14 { 15 "begin_time": "2021-07-21T06:53:00.431Z", 16 "end_time": "2021-07-21T06:53:07.443Z", 17 "entities": { 18 "name": "volume_1", 19 "size": 50, 20 "volume_id": "4c3b7a01-989a-4c34-876c-4699f3766457", 21 "volume_type": "SSD" 22 }, 23 "error_code": null, 24 "fail_reason": null, 25 "job_id": "ff8080817aa5637b017ac7d6ca9005d5", 26 "job_type": "createVolume", 27 "status": "SUCCESS" 28 }` 29 30 var expectedJobResponseData = &jobs.Job{ 31 Status: "SUCCESS", 32 Entities: jobs.JobEntity{ 33 Name: "volume_1", 34 Size: 50, 35 VolumeID: "4c3b7a01-989a-4c34-876c-4699f3766457", 36 VolumeType: "SSD", 37 }, 38 JobID: "ff8080817aa5637b017ac7d6ca9005d5", 39 JobType: "createVolume", 40 BeginTime: "2021-07-21T06:53:00.431Z", 41 EndTime: "2021-07-21T06:53:07.443Z", 42 } 43 44 func handleGetJobDetail(t *testing.T) { 45 th.Mux.HandleFunc("/jobs/ff8080817aa5637b017ac7d6ca9005d5", 46 func(w http.ResponseWriter, r *http.Request) { 47 th.TestMethod(t, r, "GET") 48 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 49 w.Header().Add("Content-Type", "application/json") 50 w.WriteHeader(http.StatusOK) 51 _, _ = fmt.Fprint(w, expectedResponse) 52 }) 53 } 54 55 func TestGetJobDetail(t *testing.T) { 56 th.SetupHTTP() 57 defer th.TeardownHTTP() 58 handleGetJobDetail(t) 59 60 actual, err := jobs.GetJobDetails(client.ServiceClient(), "ff8080817aa5637b017ac7d6ca9005d5").ExtractJob() 61 th.AssertNoErr(t, err) 62 th.AssertDeepEquals(t, expectedJobResponseData, actual) 63 }