blob: b0a765befa9529bf98d2303b8b0c266bbd98000f [file] [log] [blame]
Joe Topjian520307e2015-02-07 05:22:12 +00001package volumeattach
2
3import (
4 "testing"
5
Sreekanth Pothanis07400f32015-09-08 00:26:14 -07006 fixtures "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach/testing"
Joe Topjian520307e2015-02-07 05:22:12 +00007 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 "github.com/rackspace/gophercloud/testhelper/client"
10)
11
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070012// FirstVolumeAttachment is the first result in ListOutput.
13var FirstVolumeAttachment = VolumeAttachment{
14 Device: "/dev/vdd",
15 ID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
16 ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
17 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
18}
19
20// SecondVolumeAttachment is the first result in ListOutput.
21var SecondVolumeAttachment = VolumeAttachment{
22 Device: "/dev/vdc",
23 ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
24 ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
25 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
26}
27
28// ExpectedVolumeAttachmentSlide is the slice of results that should be parsed
29// from ListOutput, in the expected order.
30var ExpectedVolumeAttachmentSlice = []VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment}
31
32//CreatedVolumeAttachment is the parsed result from CreatedOutput.
33var CreatedVolumeAttachment = VolumeAttachment{
34 Device: "/dev/vdc",
35 ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
36 ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
37 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
38}
39
Joe Topjian520307e2015-02-07 05:22:12 +000040func TestList(t *testing.T) {
41 th.SetupHTTP()
42 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070043 fixtures.HandleListSuccessfully(t)
Joe Topjian520307e2015-02-07 05:22:12 +000044 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
45
46 count := 0
47 err := List(client.ServiceClient(), serverId).EachPage(func(page pagination.Page) (bool, error) {
48 count++
49 actual, err := ExtractVolumeAttachments(page)
50 th.AssertNoErr(t, err)
51 th.CheckDeepEquals(t, ExpectedVolumeAttachmentSlice, actual)
52
53 return true, nil
54 })
55 th.AssertNoErr(t, err)
56 th.CheckEquals(t, 1, count)
57}
58
59func TestCreate(t *testing.T) {
60 th.SetupHTTP()
61 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070062 fixtures.HandleCreateSuccessfully(t)
Joe Topjian520307e2015-02-07 05:22:12 +000063 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
64
65 actual, err := Create(client.ServiceClient(), serverId, CreateOpts{
66 Device: "/dev/vdc",
67 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
Joe Topjian520307e2015-02-07 05:22:12 +000068 }).Extract()
69 th.AssertNoErr(t, err)
70 th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual)
71}
72
73func TestGet(t *testing.T) {
74 th.SetupHTTP()
75 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070076 fixtures.HandleGetSuccessfully(t)
Joe Topjian520307e2015-02-07 05:22:12 +000077 aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
78 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
79
80 actual, err := Get(client.ServiceClient(), serverId, aId).Extract()
81 th.AssertNoErr(t, err)
82 th.CheckDeepEquals(t, &SecondVolumeAttachment, actual)
83}
84
85func TestDelete(t *testing.T) {
86 th.SetupHTTP()
87 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070088 fixtures.HandleDeleteSuccessfully(t)
Joe Topjian520307e2015-02-07 05:22:12 +000089 aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
90 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
91
92 err := Delete(client.ServiceClient(), serverId, aId).ExtractErr()
93 th.AssertNoErr(t, err)
94}