Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 1 | package volumeattach |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 6 | fixtures "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach/testing" |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 12 | // FirstVolumeAttachment is the first result in ListOutput. |
| 13 | var 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. |
| 21 | var 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. |
| 30 | var ExpectedVolumeAttachmentSlice = []VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment} |
| 31 | |
| 32 | //CreatedVolumeAttachment is the parsed result from CreatedOutput. |
| 33 | var 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 Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 40 | func TestList(t *testing.T) { |
| 41 | th.SetupHTTP() |
| 42 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 43 | fixtures.HandleListSuccessfully(t) |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 44 | 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 | |
| 59 | func TestCreate(t *testing.T) { |
| 60 | th.SetupHTTP() |
| 61 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 62 | fixtures.HandleCreateSuccessfully(t) |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 63 | 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 Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 68 | }).Extract() |
| 69 | th.AssertNoErr(t, err) |
| 70 | th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual) |
| 71 | } |
| 72 | |
| 73 | func TestGet(t *testing.T) { |
| 74 | th.SetupHTTP() |
| 75 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 76 | fixtures.HandleGetSuccessfully(t) |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 77 | 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 | |
| 85 | func TestDelete(t *testing.T) { |
| 86 | th.SetupHTTP() |
| 87 | defer th.TeardownHTTP() |
Sreekanth Pothanis | 07400f3 | 2015-09-08 00:26:14 -0700 | [diff] [blame] | 88 | fixtures.HandleDeleteSuccessfully(t) |
Joe Topjian | 520307e | 2015-02-07 05:22:12 +0000 | [diff] [blame] | 89 | 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 | } |