jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 1 | package testing |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 6 | db "github.com/gophercloud/gophercloud/openstack/db/v1/databases" |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 7 | "github.com/gophercloud/gophercloud/openstack/db/v1/instances" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/openstack/db/v1/users" |
| 9 | "github.com/gophercloud/gophercloud/pagination" |
| 10 | th "github.com/gophercloud/gophercloud/testhelper" |
| 11 | fake "github.com/gophercloud/gophercloud/testhelper/client" |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 12 | ) |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 13 | |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 14 | func TestCreate(t *testing.T) { |
| 15 | th.SetupHTTP() |
| 16 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 17 | HandleCreate(t) |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 18 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 19 | opts := instances.CreateOpts{ |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 20 | Name: "json_rack_instance", |
| 21 | FlavorRef: "1", |
Jamie Hannaford | 85f1033 | 2015-02-12 11:51:37 +0100 | [diff] [blame] | 22 | Databases: db.BatchCreateOpts{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 23 | {CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, |
| 24 | {Name: "nextround"}, |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 25 | }, |
Jamie Hannaford | 3aba0b1 | 2015-02-13 14:33:39 +0100 | [diff] [blame] | 26 | Users: users.BatchCreateOpts{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 27 | { |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 28 | Name: "demouser", |
| 29 | Password: "demopassword", |
Jamie Hannaford | 85f1033 | 2015-02-12 11:51:37 +0100 | [diff] [blame] | 30 | Databases: db.BatchCreateOpts{ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 31 | {Name: "sampledb"}, |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 32 | }, |
| 33 | }, |
| 34 | }, |
| 35 | Size: 2, |
| 36 | } |
| 37 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 38 | instance, err := instances.Create(fake.ServiceClient(), opts).Extract() |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 39 | |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 40 | th.AssertNoErr(t, err) |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 41 | th.AssertDeepEquals(t, &expectedInstance, instance) |
Jamie Hannaford | 9fdda58 | 2015-02-10 12:15:43 +0100 | [diff] [blame] | 42 | } |
Jamie Hannaford | 9068424 | 2015-02-10 12:46:07 +0100 | [diff] [blame] | 43 | |
| 44 | func TestInstanceList(t *testing.T) { |
| 45 | th.SetupHTTP() |
| 46 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 47 | HandleList(t) |
Jamie Hannaford | 9068424 | 2015-02-10 12:46:07 +0100 | [diff] [blame] | 48 | |
| 49 | pages := 0 |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 50 | err := instances.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
Jamie Hannaford | 9068424 | 2015-02-10 12:46:07 +0100 | [diff] [blame] | 51 | pages++ |
| 52 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 53 | actual, err := instances.ExtractInstances(page) |
Jamie Hannaford | 9068424 | 2015-02-10 12:46:07 +0100 | [diff] [blame] | 54 | if err != nil { |
| 55 | return false, err |
| 56 | } |
| 57 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 58 | th.CheckDeepEquals(t, []instances.Instance{expectedInstance}, actual) |
Jamie Hannaford | 9068424 | 2015-02-10 12:46:07 +0100 | [diff] [blame] | 59 | return true, nil |
| 60 | }) |
| 61 | |
| 62 | th.AssertNoErr(t, err) |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 63 | th.AssertEquals(t, 1, pages) |
Jamie Hannaford | 9068424 | 2015-02-10 12:46:07 +0100 | [diff] [blame] | 64 | } |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 65 | |
| 66 | func TestGetInstance(t *testing.T) { |
| 67 | th.SetupHTTP() |
| 68 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 69 | HandleGet(t) |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 70 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 71 | instance, err := instances.Get(fake.ServiceClient(), instanceID).Extract() |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 72 | |
| 73 | th.AssertNoErr(t, err) |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 74 | th.AssertDeepEquals(t, &expectedInstance, instance) |
Jamie Hannaford | 821015f | 2015-02-10 12:58:36 +0100 | [diff] [blame] | 75 | } |
Jamie Hannaford | 5b16b63 | 2015-02-10 13:36:23 +0100 | [diff] [blame] | 76 | |
| 77 | func TestDeleteInstance(t *testing.T) { |
| 78 | th.SetupHTTP() |
| 79 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 80 | HandleDelete(t) |
Jamie Hannaford | 5b16b63 | 2015-02-10 13:36:23 +0100 | [diff] [blame] | 81 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 82 | res := instances.Delete(fake.ServiceClient(), instanceID) |
Jamie Hannaford | 5b16b63 | 2015-02-10 13:36:23 +0100 | [diff] [blame] | 83 | th.AssertNoErr(t, res.Err) |
| 84 | } |
Jamie Hannaford | 94164fa | 2015-02-10 13:58:45 +0100 | [diff] [blame] | 85 | |
| 86 | func TestEnableRootUser(t *testing.T) { |
| 87 | th.SetupHTTP() |
| 88 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 89 | HandleEnableRoot(t) |
Jamie Hannaford | 94164fa | 2015-02-10 13:58:45 +0100 | [diff] [blame] | 90 | |
Jamie Hannaford | 3aba0b1 | 2015-02-13 14:33:39 +0100 | [diff] [blame] | 91 | expected := &users.User{Name: "root", Password: "secretsecret"} |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 92 | user, err := instances.EnableRootUser(fake.ServiceClient(), instanceID).Extract() |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 93 | |
Jamie Hannaford | 94164fa | 2015-02-10 13:58:45 +0100 | [diff] [blame] | 94 | th.AssertNoErr(t, err) |
| 95 | th.AssertDeepEquals(t, expected, user) |
| 96 | } |
Jamie Hannaford | a74d425 | 2015-02-10 15:35:01 +0100 | [diff] [blame] | 97 | |
| 98 | func TestIsRootEnabled(t *testing.T) { |
| 99 | th.SetupHTTP() |
| 100 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 101 | HandleIsRootEnabled(t) |
Jamie Hannaford | a74d425 | 2015-02-10 15:35:01 +0100 | [diff] [blame] | 102 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 103 | isEnabled, err := instances.IsRootEnabled(fake.ServiceClient(), instanceID).Extract() |
Jamie Hannaford | a74d425 | 2015-02-10 15:35:01 +0100 | [diff] [blame] | 104 | |
| 105 | th.AssertNoErr(t, err) |
| 106 | th.AssertEquals(t, true, isEnabled) |
| 107 | } |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 108 | |
Jamie Hannaford | 75e8cc4 | 2015-11-16 14:09:25 +0100 | [diff] [blame] | 109 | func TestRestart(t *testing.T) { |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 110 | th.SetupHTTP() |
| 111 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 112 | HandleRestart(t) |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 113 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 114 | res := instances.Restart(fake.ServiceClient(), instanceID) |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 115 | th.AssertNoErr(t, res.Err) |
| 116 | } |
| 117 | |
Jamie Hannaford | 75e8cc4 | 2015-11-16 14:09:25 +0100 | [diff] [blame] | 118 | func TestResize(t *testing.T) { |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 119 | th.SetupHTTP() |
| 120 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 121 | HandleResize(t) |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 122 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 123 | res := instances.Resize(fake.ServiceClient(), instanceID, "2") |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 124 | th.AssertNoErr(t, res.Err) |
| 125 | } |
| 126 | |
| 127 | func TestResizeVolume(t *testing.T) { |
| 128 | th.SetupHTTP() |
| 129 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 130 | HandleResizeVol(t) |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 131 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame^] | 132 | res := instances.ResizeVolume(fake.ServiceClient(), instanceID, 4) |
Jamie Hannaford | 219ca59 | 2015-02-10 15:59:05 +0100 | [diff] [blame] | 133 | th.AssertNoErr(t, res.Err) |
| 134 | } |