Ash Wilson | 0e5b92a | 2014-10-23 11:42:04 -0400 | [diff] [blame] | 1 | package diskconfig |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
Ash Wilson | 3883af2 | 2014-10-23 11:57:00 -0400 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/pagination" |
Ash Wilson | 0e5b92a | 2014-10-23 11:42:04 -0400 | [diff] [blame] | 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | func TestExtractGet(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
| 15 | servers.HandleServerGetSuccessfully(t) |
| 16 | |
| 17 | config, err := ExtractGet(servers.Get(client.ServiceClient(), "1234asdf")) |
| 18 | th.AssertNoErr(t, err) |
| 19 | th.CheckEquals(t, Manual, *config) |
| 20 | } |
| 21 | |
| 22 | func TestExtractUpdate(t *testing.T) { |
| 23 | th.SetupHTTP() |
| 24 | defer th.TeardownHTTP() |
| 25 | servers.HandleServerUpdateSuccessfully(t) |
| 26 | |
| 27 | r := servers.Update(client.ServiceClient(), "1234asdf", servers.UpdateOpts{ |
| 28 | Name: "new-name", |
| 29 | }) |
| 30 | config, err := ExtractUpdate(r) |
| 31 | th.AssertNoErr(t, err) |
| 32 | th.CheckEquals(t, Manual, *config) |
| 33 | } |
| 34 | |
| 35 | func TestExtractRebuild(t *testing.T) { |
| 36 | th.SetupHTTP() |
| 37 | defer th.TeardownHTTP() |
| 38 | servers.HandleRebuildSuccessfully(t, servers.SingleServerBody) |
| 39 | |
| 40 | r := servers.Rebuild(client.ServiceClient(), "1234asdf", servers.RebuildOpts{ |
| 41 | Name: "new-name", |
| 42 | AdminPass: "swordfish", |
| 43 | ImageID: "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 44 | AccessIPv4: "1.2.3.4", |
| 45 | }) |
| 46 | config, err := ExtractRebuild(r) |
| 47 | th.AssertNoErr(t, err) |
| 48 | th.CheckEquals(t, Manual, *config) |
| 49 | } |
Ash Wilson | 3883af2 | 2014-10-23 11:57:00 -0400 | [diff] [blame] | 50 | |
| 51 | func TestExtractList(t *testing.T) { |
| 52 | th.SetupHTTP() |
| 53 | defer th.TeardownHTTP() |
| 54 | servers.HandleServerListSuccessfully(t) |
| 55 | |
| 56 | pages := 0 |
| 57 | err := servers.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { |
| 58 | pages++ |
| 59 | |
| 60 | config, err := ExtractDiskConfig(page, 0) |
| 61 | th.AssertNoErr(t, err) |
| 62 | th.CheckEquals(t, Manual, *config) |
| 63 | |
| 64 | return true, nil |
| 65 | }) |
| 66 | th.AssertNoErr(t, err) |
| 67 | th.CheckEquals(t, pages, 1) |
| 68 | } |