blob: f7ef45e621a83b0fb41f5ebb66f8fe9313205fc2 [file] [log] [blame]
Jon Perritt37465a02015-02-23 14:15:04 -07001package volumeattach
2
3import (
4 "testing"
5
Sreekanth Pothanis07400f32015-09-08 00:26:14 -07006 "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
7 fixtures "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach/testing"
Jon Perritt37465a02015-02-23 14:15:04 -07008 "github.com/rackspace/gophercloud/pagination"
9 th "github.com/rackspace/gophercloud/testhelper"
10 "github.com/rackspace/gophercloud/testhelper/client"
11)
12
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070013// FirstVolumeAttachment is the first result in ListOutput.
14var FirstVolumeAttachment = volumeattach.VolumeAttachment{
15 Device: "/dev/vdd",
16 ID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
17 ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
18 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
19}
20
21// SecondVolumeAttachment is the first result in ListOutput.
22var SecondVolumeAttachment = volumeattach.VolumeAttachment{
23 Device: "/dev/vdc",
24 ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
25 ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
26 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
27}
28
29// ExpectedVolumeAttachmentSlide is the slice of results that should be parsed
30// from ListOutput, in the expected order.
31var ExpectedVolumeAttachmentSlice = []volumeattach.VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment}
32
33//CreatedVolumeAttachment is the parsed result from CreatedOutput.
34var CreatedVolumeAttachment = volumeattach.VolumeAttachment{
35 Device: "/dev/vdc",
36 ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
37 ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
38 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
39}
40
Jon Perritt37465a02015-02-23 14:15:04 -070041func TestList(t *testing.T) {
42 th.SetupHTTP()
43 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070044 fixtures.HandleListSuccessfully(t)
Jon Perritt37465a02015-02-23 14:15:04 -070045 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
46
47 count := 0
48 err := List(client.ServiceClient(), serverId).EachPage(func(page pagination.Page) (bool, error) {
49 count++
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070050 actual, err := volumeattach.ExtractVolumeAttachments(page)
Jon Perritt37465a02015-02-23 14:15:04 -070051 th.AssertNoErr(t, err)
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070052 th.CheckDeepEquals(t, ExpectedVolumeAttachmentSlice, actual)
Jon Perritt37465a02015-02-23 14:15:04 -070053
54 return true, nil
55 })
56 th.AssertNoErr(t, err)
57 th.CheckEquals(t, 1, count)
58}
59
60func TestCreate(t *testing.T) {
61 th.SetupHTTP()
62 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070063 fixtures.HandleCreateSuccessfully(t)
Jon Perritt37465a02015-02-23 14:15:04 -070064 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
65
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070066 actual, err := Create(client.ServiceClient(), serverId, volumeattach.CreateOpts{
Jon Perritt37465a02015-02-23 14:15:04 -070067 Device: "/dev/vdc",
68 VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
69 }).Extract()
70 th.AssertNoErr(t, err)
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070071 th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual)
Jon Perritt37465a02015-02-23 14:15:04 -070072}
73
74func TestGet(t *testing.T) {
75 th.SetupHTTP()
76 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070077 fixtures.HandleGetSuccessfully(t)
Jon Perritt37465a02015-02-23 14:15:04 -070078 aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
79 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
80
81 actual, err := Get(client.ServiceClient(), serverId, aId).Extract()
82 th.AssertNoErr(t, err)
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070083 th.CheckDeepEquals(t, &SecondVolumeAttachment, actual)
Jon Perritt37465a02015-02-23 14:15:04 -070084}
85
86func TestDelete(t *testing.T) {
87 th.SetupHTTP()
88 defer th.TeardownHTTP()
Sreekanth Pothanis07400f32015-09-08 00:26:14 -070089 fixtures.HandleDeleteSuccessfully(t)
Jon Perritt37465a02015-02-23 14:15:04 -070090 aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
91 serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
92
93 err := Delete(client.ServiceClient(), serverId, aId).ExtractErr()
94 th.AssertNoErr(t, err)
95}