blob: e26416cba0de46bf83866e41836012946544c3ed [file] [log] [blame]
Jon Perritt37465a02015-02-23 14:15:04 -07001package volumeattach
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func TestList(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15 os.HandleListSuccessfully(t)
16 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
17
18 count := 0
19 err := List(client.ServiceClient(), serverId).EachPage(func(page pagination.Page) (bool, error) {
20 count++
21 actual, err := os.ExtractVolumeAttachments(page)
22 th.AssertNoErr(t, err)
23 th.CheckDeepEquals(t, os.ExpectedVolumeAttachmentSlice, actual)
24
25 return true, nil
26 })
27 th.AssertNoErr(t, err)
28 th.CheckEquals(t, 1, count)
29}
30
31func TestCreate(t *testing.T) {
32 th.SetupHTTP()
33 defer th.TeardownHTTP()
34 os.HandleCreateSuccessfully(t)
35 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
36
37 actual, err := Create(client.ServiceClient(), serverId, os.CreateOpts{
38 Device: "/dev/vdc",
39 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
40 }).Extract()
41 th.AssertNoErr(t, err)
42 th.CheckDeepEquals(t, &os.CreatedVolumeAttachment, actual)
43}
44
45func TestGet(t *testing.T) {
46 th.SetupHTTP()
47 defer th.TeardownHTTP()
48 os.HandleGetSuccessfully(t)
49 aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
50 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
51
52 actual, err := Get(client.ServiceClient(), serverId, aId).Extract()
53 th.AssertNoErr(t, err)
54 th.CheckDeepEquals(t, &os.SecondVolumeAttachment, actual)
55}
56
57func TestDelete(t *testing.T) {
58 th.SetupHTTP()
59 defer th.TeardownHTTP()
60 os.HandleDeleteSuccessfully(t)
61 aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
62 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
63
64 err := Delete(client.ServiceClient(), serverId, aId).ExtractErr()
65 th.AssertNoErr(t, err)
66}