1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
14
gc "gopkg.in/check.v1"
19
testToken = "test-token"
20
testTime = "test-time"
21
testDescr = "test-description"
22
testName = "test-name"
23
testAttrProgr = "test-attribute-prog"
24
testAttrProj = "test-attribute-proj"
25
testStatus = "test-status"
28
var _ = gc.Suite(&CinderTestSuite{})
30
type CinderTestSuite struct {
35
func (s *CinderTestSuite) SetUpSuite(c *gc.C) {
41
endpoint, err := url.Parse("http://volume.testing/v2/" + testId)
42
c.Assert(err, gc.IsNil)
44
cinderClient := NewClient(
47
SetAuthHeaderFn(func() string { return testToken }, s.localDo),
49
s.client = cinderClient
52
func (s *CinderTestSuite) SetUpTest(c *gc.C) {
55
c.Skip("Only running live tests.")
58
// We want a fresh Muxer so that any paths that aren't explicitly
59
// set up by the test are treated as errors.
60
s.ServeMux = http.NewServeMux()
63
func (s *CinderTestSuite) TestCreateSnapshot(c *gc.C) {
65
snapReq := CreateSnapshotSnapshotParams{
68
Description: testDescr,
72
s.HandleFunc("/v2/"+testId+"/snapshots", func(w http.ResponseWriter, req *http.Request) {
75
c.Check(req.Header["X-Auth-Token"], gc.DeepEquals, []string{testToken})
77
reqBody, err := ioutil.ReadAll(req.Body)
78
c.Assert(err, gc.IsNil)
80
var receivedReq CreateSnapshotParams
81
err = json.Unmarshal(reqBody, &receivedReq)
82
c.Assert(err, gc.IsNil)
84
c.Check(receivedReq, gc.DeepEquals, CreateSnapshotParams{Snapshot: snapReq})
87
CreatedAt: "test-time",
88
Description: receivedReq.Snapshot.Description,
90
Name: receivedReq.Snapshot.Name,
92
Status: "test-status",
93
VolumeID: receivedReq.Snapshot.VolumeId,
95
respBody, err := json.Marshal(&CreateSnapshotResults{Snapshot: resp})
96
c.Assert(err, gc.IsNil)
98
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
99
w.(*responseWriter).StatusCode = 202
102
resp, err := s.client.CreateSnapshot(snapReq)
103
c.Assert(numCalls, gc.Equals, 1)
104
c.Assert(err, gc.IsNil)
106
c.Check(resp.Snapshot.CreatedAt, gc.Equals, testTime)
107
c.Check(resp.Snapshot.Description, gc.Equals, snapReq.Description)
108
c.Check(resp.Snapshot.ID, gc.Equals, testId)
109
c.Check(resp.Snapshot.Name, gc.Equals, snapReq.Name)
110
c.Check(resp.Snapshot.Size, gc.Equals, 1)
111
c.Check(resp.Snapshot.Status, gc.Equals, testStatus)
112
c.Check(resp.Snapshot.VolumeID, gc.Equals, snapReq.VolumeId)
116
func (s *CinderTestSuite) TestDeleteSnapshot(c *gc.C) {
118
s.HandleFunc("/v2/"+testId+"/snapshots/"+testId, func(w http.ResponseWriter, req *http.Request) {
121
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
122
w.(*responseWriter).StatusCode = 202
125
err := s.client.DeleteSnapshot(testId)
126
c.Assert(numCalls, gc.Equals, 1)
127
c.Assert(err, gc.IsNil)
130
func (s *CinderTestSuite) TestGetSnapshot(c *gc.C) {
133
s.HandleFunc("/v2/"+testId+"/snapshots/"+testId, func(w http.ResponseWriter, req *http.Request) {
136
c.Check(req.Header["X-Auth-Token"], gc.DeepEquals, []string{testToken})
140
Description: testDescr,
143
Os_Extended_Snapshot_Attributes_Progress: testAttrProgr,
144
Os_Extended_Snapshot_Attributes_ProjectID: testAttrProj,
150
respBody, err := json.Marshal(&GetSnapshotResults{Snapshot: resp})
151
c.Assert(err, gc.IsNil)
153
w.(*responseWriter).Response.StatusCode = 200
154
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
158
getResp, err := s.client.GetSnapshot(testId)
159
c.Assert(err, gc.IsNil)
160
c.Assert(numCalls, gc.Equals, 1)
162
c.Check(getResp.Snapshot.CreatedAt, gc.Not(gc.HasLen), 0)
163
c.Check(getResp.Snapshot.Description, gc.Equals, testDescr)
164
c.Check(getResp.Snapshot.ID, gc.Not(gc.HasLen), 0)
165
c.Check(getResp.Snapshot.Name, gc.Equals, testName)
166
c.Check(getResp.Snapshot.Size, gc.Equals, 1)
167
c.Check(getResp.Snapshot.Status, gc.Equals, testStatus)
168
c.Check(getResp.Snapshot.VolumeID, gc.Equals, testId)
171
func (s *CinderTestSuite) TestGetSnapshotDetail(c *gc.C) {
174
s.HandleFunc("/v2/"+testId+"/snapshots/detail", func(w http.ResponseWriter, req *http.Request) {
177
c.Check(req.Header["X-Auth-Token"], gc.DeepEquals, []string{testToken})
181
Description: testDescr,
184
Os_Extended_Snapshot_Attributes_Progress: testAttrProgr,
185
Os_Extended_Snapshot_Attributes_ProjectID: testAttrProj,
191
respBody, err := json.Marshal(&GetSnapshotsDetailResults{Snapshots: resp})
192
c.Assert(err, gc.IsNil)
194
w.(*responseWriter).Response.StatusCode = 200
195
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
198
detailGetResp, err := s.client.GetSnapshotsDetail()
199
c.Assert(err, gc.IsNil)
200
c.Assert(detailGetResp.Snapshots, gc.HasLen, 1)
201
c.Assert(numCalls, gc.Equals, 1)
203
snapshot := detailGetResp.Snapshots[0]
205
c.Check(snapshot.CreatedAt, gc.Equals, testTime)
206
c.Check(snapshot.Description, gc.Equals, testDescr)
207
c.Check(snapshot.ID, gc.Equals, testId)
208
c.Check(snapshot.Name, gc.Equals, testName)
209
c.Check(snapshot.Os_Extended_Snapshot_Attributes_Progress, gc.Equals, testAttrProgr)
210
c.Check(snapshot.Os_Extended_Snapshot_Attributes_ProjectID, gc.Equals, testAttrProj)
211
c.Check(snapshot.Size, gc.Equals, 1)
212
c.Check(snapshot.Status, gc.Equals, testStatus)
213
c.Check(snapshot.VolumeID, gc.Equals, testId)
216
func (s *CinderTestSuite) TestGetSnapshotSimple(c *gc.C) {
219
s.HandleFunc("/v2/"+testId+"/snapshots", func(w http.ResponseWriter, req *http.Request) {
222
c.Check(req.Header["X-Auth-Token"], gc.DeepEquals, []string{testToken})
226
Description: testDescr,
229
Os_Extended_Snapshot_Attributes_Progress: testAttrProgr,
230
Os_Extended_Snapshot_Attributes_ProjectID: testAttrProj,
236
respBody, err := json.Marshal(&GetSnapshotsDetailResults{Snapshots: resp})
237
c.Assert(err, gc.IsNil)
239
w.(*responseWriter).Response.StatusCode = 200
240
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
243
snapshotSimpResp, err := s.client.GetSnapshotsSimple()
244
c.Assert(numCalls, gc.Equals, 1)
245
c.Assert(err, gc.IsNil)
246
c.Assert(snapshotSimpResp.Snapshots, gc.HasLen, 1)
248
snapshot := snapshotSimpResp.Snapshots[0]
250
c.Check(snapshot.CreatedAt, gc.Equals, testTime)
251
c.Check(snapshot.Description, gc.Equals, testDescr)
252
c.Check(snapshot.ID, gc.Equals, testId)
253
c.Check(snapshot.Name, gc.Equals, testName)
254
c.Check(snapshot.Size, gc.Equals, 1)
255
c.Check(snapshot.Status, gc.Equals, testStatus)
256
c.Check(snapshot.VolumeID, gc.Equals, testId)
259
func (s *CinderTestSuite) TestShowSnapshotMetadata(c *gc.C) {
262
s.HandleFunc("/v2/"+testId+"/snapshots/"+testId+"/metadata", func(w http.ResponseWriter, req *http.Request) {
265
c.Check(req.Header["X-Auth-Token"], gc.DeepEquals, []string{testToken})
269
Description: testDescr,
272
Os_Extended_Snapshot_Attributes_Progress: testAttrProgr,
273
Os_Extended_Snapshot_Attributes_ProjectID: testAttrProj,
279
respBody, err := json.Marshal(&ShowSnapshotMetadataResults{Snapshot: resp})
280
c.Assert(err, gc.IsNil)
282
w.(*responseWriter).Response.StatusCode = 200
283
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
286
resp, err := s.client.ShowSnapshotMetadata(testId)
287
c.Assert(err, gc.IsNil)
289
c.Check(resp.Snapshot.CreatedAt, gc.Equals, testTime)
290
c.Check(resp.Snapshot.Description, gc.Equals, testDescr)
291
c.Check(resp.Snapshot.ID, gc.Equals, testId)
292
c.Check(resp.Snapshot.Name, gc.Equals, testName)
293
c.Check(resp.Snapshot.Size, gc.Equals, 1)
294
c.Check(resp.Snapshot.Status, gc.Equals, testStatus)
295
c.Check(resp.Snapshot.VolumeID, gc.Equals, testId)
298
func (s *CinderTestSuite) TestUpdateSnapshot(c *gc.C) {
300
updateReq := UpdateSnapshotSnapshotParams{testName, testDescr}
303
s.HandleFunc("/v2/"+testId+"/snapshots/"+testId, func(w http.ResponseWriter, req *http.Request) {
306
c.Check(req.Header["X-Auth-Token"], gc.DeepEquals, []string{testToken})
308
reqBody, err := ioutil.ReadAll(req.Body)
309
c.Assert(err, gc.IsNil)
311
var receivedReq UpdateSnapshotParams
312
err = json.Unmarshal(reqBody, &receivedReq)
313
c.Assert(err, gc.IsNil)
315
c.Check(receivedReq, gc.DeepEquals, UpdateSnapshotParams{Snapshot: updateReq})
319
Description: updateReq.Description,
321
Name: updateReq.Name,
327
respBody, err := json.Marshal(&UpdateSnapshotResults{Snapshot: resp})
328
c.Assert(err, gc.IsNil)
330
w.(*responseWriter).Response.StatusCode = 200
331
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
334
resp, err := s.client.UpdateSnapshot(testId, updateReq)
335
c.Assert(numCalls, gc.Equals, 1)
336
c.Assert(err, gc.IsNil)
338
c.Check(resp.Snapshot.CreatedAt, gc.Equals, testTime)
339
c.Check(resp.Snapshot.Description, gc.Equals, updateReq.Description)
340
c.Check(resp.Snapshot.ID, gc.Equals, testId)
341
c.Check(resp.Snapshot.Name, gc.Equals, updateReq.Name)
342
c.Check(resp.Snapshot.Size, gc.Equals, 1)
343
c.Check(resp.Snapshot.Status, gc.Equals, testStatus)
344
c.Check(resp.Snapshot.VolumeID, gc.Equals, testId)
347
func (s *CinderTestSuite) TestUpdateSnapshotMetadata(c *gc.C) {
350
s.HandleFunc("/v2/"+testId+"/snapshots/"+testId+"/metadata", func(w http.ResponseWriter, req *http.Request) {
353
c.Check(req.Header["X-Auth-Token"], gc.DeepEquals, []string{testToken})
355
reqBody, err := ioutil.ReadAll(req.Body)
356
c.Assert(err, gc.IsNil)
358
var receivedReq UpdateSnapshotMetadataParams
359
err = json.Unmarshal(reqBody, &receivedReq)
360
c.Assert(err, gc.IsNil)
362
c.Check(receivedReq.Metadata.Key, gc.DeepEquals, "test-key")
365
Key string `json:"key"`
367
Key: receivedReq.Metadata.Key,
370
respBody, err := json.Marshal(&UpdateSnapshotMetadataResults{Metadata: resp})
371
c.Assert(err, gc.IsNil)
373
w.(*responseWriter).Response.StatusCode = 200
374
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
377
resp, err := s.client.UpdateSnapshotMetadata(testId, "test-key")
378
c.Assert(numCalls, gc.Equals, 1)
379
c.Assert(err, gc.IsNil)
381
c.Check(resp.Metadata.Key, gc.Equals, "test-key")
384
func (s *CinderTestSuite) TestCreateVolume(c *gc.C) {
385
req := CreateVolumeVolumeParams{
386
Description: testDescr,
392
s.HandleFunc("/v2/"+testId+"/volumes", func(w http.ResponseWriter, req *http.Request) {
395
reqBody, err := ioutil.ReadAll(req.Body)
396
c.Assert(err, gc.IsNil)
398
var receivedReq CreateVolumeParams
399
err = json.Unmarshal(reqBody, &receivedReq)
400
c.Assert(err, gc.IsNil)
403
AvailabilityZone: receivedReq.Volume.AvailabilityZone,
404
Bootable: fmt.Sprintf("%v", receivedReq.Volume.Bootable),
405
CreatedAt: "test-time",
406
Description: receivedReq.Volume.Description,
407
Name: receivedReq.Volume.Name,
408
Size: receivedReq.Volume.Size,
412
VolumeType: "test-volume-type",
415
respBody, err := json.Marshal(&CreateVolumeResults{Volume: resp})
416
c.Assert(err, gc.IsNil)
418
w.(*responseWriter).Response.StatusCode = 202
419
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
420
c.Assert(w.(*responseWriter).Body, gc.NotNil)
423
resp, err := s.client.CreateVolume(req)
424
c.Assert(numCalls, gc.Equals, 1)
425
c.Assert(err, gc.IsNil)
427
c.Check(resp.Volume.Name, gc.Equals, req.Name)
428
c.Check(resp.Volume.AvailabilityZone, gc.Equals, req.AvailabilityZone)
429
c.Check(resp.Volume.Bootable, gc.Equals, fmt.Sprintf("%v", req.Bootable))
430
c.Check(resp.Volume.Description, gc.Equals, req.Description)
431
c.Check(resp.Volume.Size, gc.Equals, req.Size)
432
c.Check(resp.Volume.SnapshotID, gc.Equals, testId)
433
c.Check(resp.Volume.SourceVolid, gc.Equals, testId)
434
c.Check(resp.Volume.Status, gc.Equals, testStatus)
435
c.Check(resp.Volume.VolumeType, gc.Equals, "test-volume-type")
438
func (s *CinderTestSuite) TestDeleteVolume(c *gc.C) {
441
s.HandleFunc("/v2/"+testId+"/volumes/"+testId, func(w http.ResponseWriter, req *http.Request) {
444
w.(*responseWriter).Response.StatusCode = 202
445
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer([]byte{}))
448
err := s.client.DeleteVolume(testId)
449
c.Assert(numCalls, gc.Equals, 1)
450
c.Assert(err, gc.IsNil)
453
func (s *CinderTestSuite) TestUpdateVolume(c *gc.C) {
455
updateReq := UpdateVolumeVolumeParams{testName, testDescr}
458
s.HandleFunc("/v2/"+testId+"/volumes/"+testId, func(w http.ResponseWriter, req *http.Request) {
461
reqBody, err := ioutil.ReadAll(req.Body)
462
c.Assert(err, gc.IsNil)
464
var receivedReq UpdateVolumeParams
465
err = json.Unmarshal(reqBody, &receivedReq)
466
c.Assert(err, gc.IsNil)
469
AvailabilityZone: "test-avail-zone",
471
CreatedAt: "test-time",
472
Description: receivedReq.Volume.Description,
473
Name: receivedReq.Volume.Name,
478
VolumeType: "test-volume-type",
481
respBody, err := json.Marshal(&CreateVolumeResults{Volume: resp})
482
c.Assert(err, gc.IsNil)
484
w.(*responseWriter).Response.StatusCode = 200
485
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewReader(respBody))
486
c.Assert(w.(*responseWriter).Body, gc.NotNil)
489
resp, err := s.client.UpdateVolume(testId, updateReq)
490
c.Assert(numCalls, gc.Equals, 1)
491
c.Assert(err, gc.IsNil)
493
c.Check(resp.Volume.Name, gc.Equals, updateReq.Name)
494
c.Check(resp.Volume.AvailabilityZone, gc.Equals, "test-avail-zone")
495
c.Check(resp.Volume.Description, gc.Equals, updateReq.Description)
496
c.Check(resp.Volume.Size, gc.Equals, 1)
497
c.Check(resp.Volume.SnapshotID, gc.Equals, testId)
498
c.Check(resp.Volume.SourceVolid, gc.Equals, testId)
499
c.Check(resp.Volume.Status, gc.Equals, testStatus)
500
c.Check(resp.Volume.VolumeType, gc.Equals, "test-volume-type")
503
func (s *CinderTestSuite) TestUpdateVolumeType(c *gc.C) {
506
s.HandleFunc("/v2/"+testId+"/types/"+testId, func(w http.ResponseWriter, req *http.Request) {
511
Capabilities string `json:"capabilities"`
512
} `json:"extra_specs"`
513
ID string `json:"id"`
514
Name string `json:"name"`
520
respBody, err := json.Marshal(&UpdateVolumeTypeResults{VolumeType: resp})
521
c.Assert(err, gc.IsNil)
523
w.(*responseWriter).Response.StatusCode = 200
524
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
527
resp, err := s.client.UpdateVolumeType(testId, "test-volume-type")
528
c.Assert(numCalls, gc.Equals, 1)
529
c.Assert(err, gc.IsNil)
531
c.Check(resp.VolumeType.Name, gc.Equals, testName)
532
c.Check(resp.VolumeType.ID, gc.Equals, testId)
535
func (s *CinderTestSuite) TestUpdateVolumeTypeExtraSpecs(c *gc.C) {
538
testType = "test-type"
539
testSpecs = "test-xtra-specs"
543
s.HandleFunc("/v2/"+testId+"/types/"+testId, func(w http.ResponseWriter, req *http.Request) {
546
reqBody, err := ioutil.ReadAll(req.Body)
547
c.Assert(err, gc.IsNil)
549
var receivedReq UpdateVolumeTypeExtraSpecsParams
550
err = json.Unmarshal(reqBody, &receivedReq)
551
c.Assert(err, gc.IsNil)
552
c.Check(receivedReq.ExtraSpecs, gc.Equals, testSpecs)
553
c.Check(receivedReq.VolumeType, gc.Equals, testType)
557
Capabilities string `json:"capabilities"`
558
} `json:"extra_specs"`
559
ID string `json:"id"`
560
Name string `json:"name"`
565
Capabilities string `json:"capabilities"`
567
Capabilities: testSpecs,
571
respBody, err := json.Marshal(&UpdateVolumeTypeResults{VolumeType: resp})
572
c.Assert(err, gc.IsNil)
574
w.(*responseWriter).Response.StatusCode = 200
575
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
578
resp, err := s.client.UpdateVolumeTypeExtraSpecs(testId, testType, testSpecs)
579
c.Assert(numCalls, gc.Equals, 1)
580
c.Assert(err, gc.IsNil)
582
c.Check(resp.VolumeType.ExtraSpecs.Capabilities, gc.Equals, testSpecs)
583
c.Check(resp.VolumeType.ID, gc.Equals, testId)
584
c.Check(resp.VolumeType.Name, gc.Equals, testName)
587
func (s *CinderTestSuite) TestGetVolumesDetail(c *gc.C) {
590
s.HandleFunc("/v2/"+testId+"/volumes/", func(w http.ResponseWriter, req *http.Request) {
594
AvailabilityZone: "test-availability-zone",
596
Description: testDescr,
599
Os_Vol_Host_Attr_Host: "test-host",
600
Os_Vol_Tenant_Attr_TenantID: testId,
605
VolumeType: "test-volume-type",
608
respBody, err := json.Marshal(&GetVolumesDetailResults{Volumes: resp})
609
c.Assert(err, gc.IsNil)
611
w.(*responseWriter).Response.StatusCode = 200
612
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
615
resp, err := s.client.GetVolumesDetail()
616
c.Assert(numCalls, gc.Equals, 1)
617
c.Assert(err, gc.IsNil)
618
c.Assert(resp.Volumes, gc.HasLen, 1)
620
volume := resp.Volumes[0]
622
c.Check(volume.AvailabilityZone, gc.Equals, "test-availability-zone")
623
c.Check(volume.CreatedAt, gc.Equals, testTime)
624
c.Check(volume.Description, gc.Equals, testDescr)
625
c.Check(volume.ID, gc.Equals, testId)
626
c.Check(volume.Name, gc.Equals, testName)
627
c.Check(volume.Os_Vol_Host_Attr_Host, gc.Equals, "test-host")
628
c.Check(volume.Os_Vol_Tenant_Attr_TenantID, gc.Equals, testId)
629
c.Check(volume.Size, gc.Equals, 1)
630
c.Check(volume.SnapshotID, gc.Equals, testId)
631
c.Check(volume.SourceVolid, gc.Equals, testId)
632
c.Check(volume.Status, gc.Equals, testStatus)
633
c.Check(volume.VolumeType, gc.Equals, "test-volume-type")
636
func (s *CinderTestSuite) TestGetVolumesSimple(c *gc.C) {
639
s.HandleFunc("/v2/"+testId+"/volumes", func(w http.ResponseWriter, req *http.Request) {
647
respBody, err := json.Marshal(&GetVolumesSimpleResults{Volumes: resp})
648
c.Assert(err, gc.IsNil)
650
w.(*responseWriter).Response.StatusCode = 200
651
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
654
resp, err := s.client.GetVolumesSimple()
655
c.Assert(numCalls, gc.Equals, 1)
656
c.Assert(err, gc.IsNil)
657
c.Assert(resp.Volumes, gc.HasLen, 1)
659
volume := resp.Volumes[0]
661
c.Check(volume.ID, gc.Equals, testId)
662
c.Check(volume.Name, gc.Equals, testName)
665
func (s *CinderTestSuite) TestCreateVolumeType(c *gc.C) {
666
origReq := CreateVolumeTypeVolumeTypeParams{
667
Name: "test-volume-type",
668
ExtraSpecs: CreateVolumeTypeVolumeTypeExtraSpecsParams{
674
s.HandleFunc("/v2/"+testId+"/types", func(w http.ResponseWriter, req *http.Request) {
677
reqBody, err := ioutil.ReadAll(req.Body)
678
c.Assert(err, gc.IsNil)
680
var receivedReq CreateVolumeTypeParams
681
err = json.Unmarshal(reqBody, &receivedReq)
682
c.Assert(err, gc.IsNil)
684
c.Check(receivedReq.VolumeType, gc.DeepEquals, origReq)
688
Capabilities string `json:"capabilities"`
689
} `json:"extra_specs"`
690
ID string `json:"id"`
691
Name string `json:"name"`
695
Capabilities string `json:"capabilities"`
697
Capabilities: receivedReq.VolumeType.ExtraSpecs.Capabilities,
699
Name: receivedReq.VolumeType.Name,
702
respBody, err := json.Marshal(&CreateVolumeTypeResults{VolumeType: resp})
703
c.Assert(err, gc.IsNil)
705
w.(*responseWriter).StatusCode = 200
706
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
709
resp, err := s.client.CreateVolumeType(origReq)
710
c.Assert(err, gc.IsNil)
711
c.Assert(resp.VolumeType.ID, gc.Not(gc.HasLen), 0)
713
c.Check(resp.VolumeType.ExtraSpecs.Capabilities, gc.Equals, origReq.ExtraSpecs.Capabilities)
714
c.Check(resp.VolumeType.Name, gc.Equals, origReq.Name)
717
func (s *CinderTestSuite) TestDeleteVolumeType(c *gc.C) {
720
s.HandleFunc("/v2/"+testId+"/types/", func(w http.ResponseWriter, req *http.Request) {
723
w.(*responseWriter).StatusCode = 202
724
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer([]byte{}))
727
err := s.client.DeleteVolumeType(testId)
728
c.Assert(numCalls, gc.Equals, 1)
729
c.Assert(err, gc.IsNil)
732
func (s *CinderTestSuite) TestGetVolumeType(c *gc.C) {
735
s.HandleFunc("/v2/"+testId+"/types/"+testId, func(w http.ResponseWriter, req *http.Request) {
740
Capabilities string `json:"capabilities"`
741
} `json:"extra_specs"`
742
ID string `json:"id"`
743
Name string `json:"name"`
747
Capabilities string `json:"capabilities"`
749
Capabilities: "test-capability",
754
respBody, err := json.Marshal(&GetVolumeTypeResults{VolumeType: resp})
755
c.Assert(err, gc.IsNil)
757
w.(*responseWriter).StatusCode = 200
758
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
761
resp, err := s.client.GetVolumeType(testId)
762
c.Assert(numCalls, gc.Equals, 1)
763
c.Assert(err, gc.IsNil)
764
c.Assert(resp.VolumeType.ID, gc.Not(gc.HasLen), 0)
766
c.Check(resp.VolumeType.ExtraSpecs.Capabilities, gc.Equals, "test-capability")
767
c.Check(resp.VolumeType.Name, gc.Equals, testName)
770
func (s *CinderTestSuite) TestGetVolumeTypes(c *gc.C) {
773
s.HandleFunc("/v2/"+testId+"/types", func(w http.ResponseWriter, req *http.Request) {
776
resp := []VolumeType{{
779
Capabilities string `json:"capabilities"`
781
Capabilities: "test-capability",
786
respBody, err := json.Marshal(&GetVolumeTypesResults{VolumeTypes: resp})
787
c.Assert(err, gc.IsNil)
789
w.(*responseWriter).StatusCode = 200
790
w.(*responseWriter).Body = ioutil.NopCloser(bytes.NewBuffer(respBody))
793
resp, err := s.client.GetVolumeTypes()
794
c.Assert(numCalls, gc.Equals, 1)
795
c.Assert(err, gc.IsNil)
796
c.Assert(resp.VolumeTypes, gc.HasLen, 1)
798
volumeType := resp.VolumeTypes[0]
800
c.Check(volumeType.ExtraSpecs.Capabilities, gc.Equals, "test-capability")
801
c.Check(volumeType.Name, gc.Equals, testName)
802
c.Check(volumeType.ID, gc.Equals, testId)
805
func (s *CinderTestSuite) localDo(req *http.Request) (*http.Response, error) {
806
handler, matchedPattern := s.Handler(req)
807
if matchedPattern == "" {
808
return nil, fmt.Errorf("no test handler registered for %s", req.URL.Path)
810
fmt.Println(matchedPattern)
812
var response http.Response
813
handler.ServeHTTP(&responseWriter{&response}, req)
815
return &response, nil
818
type responseWriter struct {
822
func (w *responseWriter) Header() http.Header {
823
return w.Response.Header
826
func (w *responseWriter) Write(data []byte) (int, error) {
827
return len(data), w.Response.Write(bytes.NewBuffer(data))
830
func (w *responseWriter) WriteHeader(statusCode int) {
831
w.Response.StatusCode = statusCode