blob: dd8d2b7dfa7525d1ef8542b2c9f0ea986e7e4a07 [file] [log] [blame]
Ash Wilson0e5b92a2014-10-23 11:42:04 -04001package diskconfig
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
Ash Wilson3883af22014-10-23 11:57:00 -04007 "github.com/rackspace/gophercloud/pagination"
Ash Wilson0e5b92a2014-10-23 11:42:04 -04008 th "github.com/rackspace/gophercloud/testhelper"
9 "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func 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
22func 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
35func 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 Wilson3883af22014-10-23 11:57:00 -040050
51func 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}