This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
fixtures.go
173 lines (165 loc) · 4.98 KB
/
fixtures.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/huaweicloud/golangsdk/openstack/cbr/v3/tasks"
th "github.com/huaweicloud/golangsdk/testhelper"
"github.com/huaweicloud/golangsdk/testhelper/client"
)
const (
expectedGetResponse = `
{
"operation_log" : {
"status" : "success",
"provider_id" : "0daac4c5-6707-4851-97ba-169e36266b66",
"checkpoint_id" : "b432511f-d889-428f-8b0e-5f47c524c6b6",
"updated_at" : "2019-05-23T14:35:23.584418",
"error_info" : {
"message" : "",
"code" : ""
},
"started_at" : "2019-05-23T14:31:36.007230",
"id" : "4827f2da-b008-4507-ab7d-42d0df5ed912",
"extra_info" : {
"resource" : {
"type" : "OS::Nova::Server",
"id" : "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
"name" : "ECS-0001"
},
"backup" : {
"backup_name" : "manualbk_1234",
"backup_id" : "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1"
},
"common" : {
"progress" : 100,
"request_id" : "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc"
}
},
"ended_at" : "2019-05-23T14:35:23.511155",
"created_at" : "2019-05-23T14:31:36.039365",
"operation_type" : "backup",
"project_id" : "04f1829c788037ac2fb8c01eb2b04b95"
}
}`
expectedListResponse = `
{
"operation_logs" : [ {
"status" : "success",
"provider_id" : "0daac4c5-6707-4851-97ba-169e36266b66",
"checkpoint_id" : "b432511f-d889-428f-8b0e-5f47c524c6b6",
"updated_at" : "2019-05-23T14:35:23.584418",
"error_info" : {
"message" : "",
"code" : ""
},
"started_at" : "2019-05-23T14:31:36.007230",
"id" : "4827f2da-b008-4507-ab7d-42d0df5ed912",
"extra_info" : {
"resource" : {
"type" : "OS::Nova::Server",
"id" : "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
"name" : "ECS-0001"
},
"backup" : {
"backup_name" : "manualbk_1234",
"backup_id" : "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1"
},
"common" : {
"progress" : 100,
"request_id" : "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc"
}
},
"ended_at" : "2019-05-23T14:35:23.511155",
"created_at" : "2019-05-23T14:31:36.039365",
"operation_type" : "backup",
"project_id" : "04f1829c788037ac2fb8c01eb2b04b95"
} ],
"count" : 1
}`
)
var (
expectedGetResponseData = &tasks.OperationLog{
Status: "success",
ProviderID: "0daac4c5-6707-4851-97ba-169e36266b66",
CheckpointID: "b432511f-d889-428f-8b0e-5f47c524c6b6",
UpdatedAt: "2019-05-23T14:35:23.584418",
ErrorInfo: tasks.OpErrorInfo{
Message: "",
Code: "",
},
StartedAt: "2019-05-23T14:31:36.007230",
ID: "4827f2da-b008-4507-ab7d-42d0df5ed912",
ExtraInfo: tasks.OpExtraInfo{
Resource: tasks.Resource{
Type: "OS::Nova::Server",
ID: "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
Name: "ECS-0001",
},
Backup: tasks.OpExtendInfoBackup{
BackupName: "manualbk_1234",
BackupID: "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1",
},
Common: tasks.OpExtendInfoCommon{
Progress: 100,
RequestID: "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc",
},
},
EndedAt: "2019-05-23T14:35:23.511155",
CreatedAt: "2019-05-23T14:31:36.039365",
OperationType: "backup",
ProjectID: "04f1829c788037ac2fb8c01eb2b04b95",
}
expectedListResponseData = &[]tasks.OperationLog{
{
Status: "success",
ProviderID: "0daac4c5-6707-4851-97ba-169e36266b66",
CheckpointID: "b432511f-d889-428f-8b0e-5f47c524c6b6",
UpdatedAt: "2019-05-23T14:35:23.584418",
ErrorInfo: tasks.OpErrorInfo{
Message: "",
Code: "",
},
StartedAt: "2019-05-23T14:31:36.007230",
ID: "4827f2da-b008-4507-ab7d-42d0df5ed912",
ExtraInfo: tasks.OpExtraInfo{
Resource: tasks.Resource{
Type: "OS::Nova::Server",
ID: "1dab32fa-ebf2-415a-ab0b-eabe6353bc86",
Name: "ECS-0001",
},
Backup: tasks.OpExtendInfoBackup{
BackupName: "manualbk_1234",
BackupID: "0e5d0ef6-7f0a-4890-b98c-cb12490e31c1",
},
Common: tasks.OpExtendInfoCommon{
Progress: 100,
RequestID: "req-cdb98cc4-e87b-4f40-9b4a-57ec036620bc",
},
},
EndedAt: "2019-05-23T14:35:23.511155",
CreatedAt: "2019-05-23T14:31:36.039365",
OperationType: "backup",
ProjectID: "04f1829c788037ac2fb8c01eb2b04b95",
},
}
)
func handleTaskGet(t *testing.T) {
th.Mux.HandleFunc("/operation-logs/4827f2da-b008-4507-ab7d-42d0df5ed912",
func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = fmt.Fprint(w, expectedGetResponse)
})
}
func handleTaskList(t *testing.T) {
th.Mux.HandleFunc("/operation-logs", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = fmt.Fprint(w, expectedListResponse)
})
}