Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 1 | package volumeattach |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach" |
| 7 | fixtures "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach/testing" |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/pagination" |
| 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | "github.com/rackspace/gophercloud/testhelper/client" |
| 11 | ) |
| 12 | |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 13 | // FirstVolumeAttachment is the first result in ListOutput. |
| 14 | var 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. |
| 22 | var 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. |
| 31 | var ExpectedVolumeAttachmentSlice = []volumeattach.VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment} |
| 32 | |
| 33 | //CreatedVolumeAttachment is the parsed result from CreatedOutput. |
| 34 | var 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 Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 41 | func TestList(t *testing.T) { |
| 42 | th.SetupHTTP() |
| 43 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 44 | fixtures.HandleListSuccessfully(t) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 45 | 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 Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 50 | actual, err := volumeattach.ExtractVolumeAttachments(page) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 51 | th.AssertNoErr(t, err) |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 52 | th.CheckDeepEquals(t, ExpectedVolumeAttachmentSlice, actual) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 53 | |
| 54 | return true, nil |
| 55 | }) |
| 56 | th.AssertNoErr(t, err) |
| 57 | th.CheckEquals(t, 1, count) |
| 58 | } |
| 59 | |
| 60 | func TestCreate(t *testing.T) { |
| 61 | th.SetupHTTP() |
| 62 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 63 | fixtures.HandleCreateSuccessfully(t) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 64 | serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" |
| 65 | |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 66 | actual, err := Create(client.ServiceClient(), serverId, volumeattach.CreateOpts{ |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 67 | Device: "/dev/vdc", |
| 68 | VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804", |
| 69 | }).Extract() |
| 70 | th.AssertNoErr(t, err) |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 71 | th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | func TestGet(t *testing.T) { |
| 75 | th.SetupHTTP() |
| 76 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 77 | fixtures.HandleGetSuccessfully(t) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 78 | 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 Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 83 | th.CheckDeepEquals(t, &SecondVolumeAttachment, actual) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | func TestDelete(t *testing.T) { |
| 87 | th.SetupHTTP() |
| 88 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 89 | fixtures.HandleDeleteSuccessfully(t) |
Jon Perritt | 37465a0 | 2015-02-23 14:15:04 -0700 | [diff] [blame] | 90 | 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 | } |