blob: e0d5fdf458d7d069bb24d0f34405b41e73c66262 [file] [log] [blame]
Joe Topjian520307e2015-02-07 05:22:12 +00001package volumeattach
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/pagination"
7 th "github.com/rackspace/gophercloud/testhelper"
8 "github.com/rackspace/gophercloud/testhelper/client"
9)
10
11func TestList(t *testing.T) {
12 th.SetupHTTP()
13 defer th.TeardownHTTP()
14 HandleListSuccessfully(t)
15 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
16
17 count := 0
18 err := List(client.ServiceClient(), serverId).EachPage(func(page pagination.Page) (bool, error) {
19 count++
20 actual, err := ExtractVolumeAttachments(page)
21 th.AssertNoErr(t, err)
22 th.CheckDeepEquals(t, ExpectedVolumeAttachmentSlice, actual)
23
24 return true, nil
25 })
26 th.AssertNoErr(t, err)
27 th.CheckEquals(t, 1, count)
28}
29
30func TestCreate(t *testing.T) {
31 th.SetupHTTP()
32 defer th.TeardownHTTP()
33 HandleCreateSuccessfully(t)
34 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
35
36 actual, err := Create(client.ServiceClient(), serverId, CreateOpts{
37 Device: "/dev/vdc",
38 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
39 ServerID: serverId,
40 }).Extract()
41 th.AssertNoErr(t, err)
42 th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual)
43}
44
45func TestGet(t *testing.T) {
46 th.SetupHTTP()
47 defer th.TeardownHTTP()
48 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, &SecondVolumeAttachment, actual)
55}
56
57func TestDelete(t *testing.T) {
58 th.SetupHTTP()
59 defer th.TeardownHTTP()
60 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}