@@ -27,97 +27,20 @@ import (
2727)
2828
2929func TestListAccounts (t * testing.T ) {
30+ apiName := "listAccountsResponse"
3031 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
31- resp := `
32- {
33- "listaccountsresponse": {
34- "account": [
35- {
36- "accountdetails": {
37- "key0": "value0",
38- "key1": "value1"
39- },
40- "accounttype": 1,
41- "cpuavailable": "Unlimited",
42- "cpulimit": "Unlimited",
43- "cputotal": 1,
44- "domain": "ROOT",
45- "domainid": "62f5fe2e-5f5a-11e5-bc86-0242ac11180a",
46- "groups": [],
47- "id": "62f61a73-5f5a-11e5-bc86-0242ac11180a",
48- "ipavailable": "Unlimited",
49- "iplimit": "Unlimited",
50- "iptotal": 1,
51- "isdefault": true,
52- "memoryavailable": "Unlimited",
53- "memorylimit": "Unlimited",
54- "memorytotal": 512,
55- "name": "admin",
56- "networkavailable": "Unlimited",
57- "networklimit": "Unlimited",
58- "networktotal": 1,
59- "primarystorageavailable": "Unlimited",
60- "primarystoragelimit": "Unlimited",
61- "primarystoragetotal": 2,
62- "projectavailable": "Unlimited",
63- "projectlimit": "Unlimited",
64- "projecttotal": 1,
65- "receivedbytes": 100,
66- "secondarystorageavailable": "Unlimited",
67- "secondarystoragelimit": "Unlimited",
68- "secondarystoragetotal": 0,
69- "sentbytes": 100,
70- "snapshotavailable": "Unlimited",
71- "snapshotlimit": "Unlimited",
72- "snapshottotal": 0,
73- "state": "enabled",
74- "templateavailable": "Unlimited",
75- "templatelimit": "Unlimited",
76- "templatetotal": 0,
77- "user": [
78- {
79- "account": "admin",
80- "accountid": "62f61a73-5f5a-11e5-bc86-0242ac11180a",
81- "accounttype": 1,
82- "apikey": "BFCyYeY0HhhrvNWC7FBwHTlso52ow3XWZUzNuiv03jmJOQn-5UH5BTVRVheiBnaRfYFE9yOzjwiqkbahq9P-Rw",
83- "created": "2015-09-20T05:42:31+0000",
84- "domain": "ROOT",
85- "domainid": "62f5fe2e-5f5a-11e5-bc86-0242ac11180a",
86- "email": "admin@mailprovider.com",
87- "firstname": "Admin",
88- "id": "62f6394b-5f5a-11e5-bc86-0242ac11180a",
89- "iscallerchilddomain": false,
90- "isdefault": true,
91- "lastname": "User",
92- "secretkey": "Em1UPdKTYEDaUxPXKtpqy_1uYluHWU2ZHotPi-VnBi_-MOEUAANoFHg3ycDProluDzYAXmT3YRssk367ylr_4A",
93- "state": "enabled",
94- "username": "admin"
95- }
96- ],
97- "vmavailable": "Unlimited",
98- "vmlimit": "Unlimited",
99- "vmrunning": 1,
100- "vmtotal": 1,
101- "volumeavailable": "Unlimited",
102- "volumelimit": "Unlimited",
103- "volumetotal": 1,
104- "vpcavailable": "Unlimited",
105- "vpclimit": "Unlimited",
106- "vpctotal": 0
107- }
108- ],
109- "count": 1
110- }
111- }
112- `
113- fmt .Fprintln (w , resp )
32+ resp , err := ReadData (apiName , "AccountService" )
33+ if err != nil {
34+ t .Errorf ("Failed to read response data, due to: %v" , err )
35+ return
36+ }
37+ fmt .Fprintln (w , resp [apiName ])
11438 }))
11539 defer server .Close ()
11640
11741 client := newClient (server .URL , "APIKEY" , "SECRETKEY" , true , true )
11842 p := client .Account .NewListAccountsParams ()
11943 acc , _ := client .Account .ListAccounts (p )
120-
12144 accounts := acc .Accounts
12245 if len (accounts ) != 1 {
12346 t .Errorf ("length: actual %d, expected 1" , len (accounts ))
@@ -141,82 +64,14 @@ func TestListAccounts(t *testing.T) {
14164}
14265
14366func TestCreateAccounts (t * testing.T ) {
67+ apiName := "createAccountsResponse"
14468 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
145- resp := `
146- {
147- "createaccountresponse": {
148- "account": {
149- "accountdetails": {
150- "key0": "value0",
151- "key1": "value1"
152- },
153- "accounttype": 2,
154- "cpuavailable": "40",
155- "cpulimit": "40",
156- "cputotal": 0,
157- "domain": "ROOT",
158- "domainid": "62f5fe2e-5f5a-11e5-bc86-0242ac11180a",
159- "groups": [],
160- "id": "c9cb9df8-dcd5-44c5-a40d-2e7d266669a6",
161- "ipavailable": "20",
162- "iplimit": "20",
163- "iptotal": 0,
164- "isdefault": false,
165- "memoryavailable": "40960",
166- "memorylimit": "40960",
167- "memorytotal": 0,
168- "name": "user01",
169- "networkavailable": "20",
170- "networklimit": "20",
171- "networktotal": 0,
172- "primarystorageavailable": "200",
173- "primarystoragelimit": "200",
174- "primarystoragetotal": 0,
175- "projectavailable": "Unlimited",
176- "projectlimit": "Unlimited",
177- "projecttotal": 0,
178- "secondarystorageavailable": "400",
179- "secondarystoragelimit": "400",
180- "secondarystoragetotal": 0,
181- "snapshotavailable": "20",
182- "snapshotlimit": "20",
183- "snapshottotal": 0,
184- "state": "enabled",
185- "templateavailable": "20",
186- "templatelimit": "20",
187- "templatetotal": 0,
188- "user": [
189- {
190- "account": "user01",
191- "accountid": "c9cb9df8-dcd5-44c5-a40d-2e7d266669a6",
192- "accounttype": 2,
193- "created": "2016-07-26T02:17:17+0000",
194- "domain": "ROOT",
195- "domainid": "62f5fe2e-5f5a-11e5-bc86-0242ac11180a",
196- "email": "user01@example.com",
197- "firstname": "user01",
198- "id": "1d69ac45-a8f7-469c-ab24-d2b0382fa8be",
199- "iscallerchilddomain": false,
200- "isdefault": false,
201- "lastname": "user01",
202- "state": "enabled",
203- "username": "user01"
204- }
205- ],
206- "vmavailable": "20",
207- "vmlimit": "20",
208- "vmtotal": 0,
209- "volumeavailable": "20",
210- "volumelimit": "20",
211- "volumetotal": 0,
212- "vpcavailable": "20",
213- "vpclimit": "20",
214- "vpctotal": 0
215- }
216- }
217- }
218- `
219- fmt .Fprintln (w , resp )
69+ resp , err := ReadData (apiName , "AccountService" )
70+ if err != nil {
71+ t .Errorf ("Failed to read response data, due to: %v" , err )
72+ return
73+ }
74+ fmt .Fprintln (w , resp [apiName ])
22075 }))
22176 defer server .Close ()
22277
0 commit comments