Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 1 | package servers |
| 2 | |
| 3 | import ( |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 4 | "net/http" |
| 5 | "testing" |
| 6 | |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/pagination" |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | "github.com/rackspace/gophercloud/testhelper/client" |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 10 | ) |
| 11 | |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 12 | func TestListServers(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
Ash Wilson | a70510a | 2014-10-23 11:54:03 -0400 | [diff] [blame] | 15 | HandleServerListSuccessfully(t) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 16 | |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 17 | pages := 0 |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 18 | err := List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 19 | pages++ |
| 20 | |
| 21 | actual, err := ExtractServers(page) |
| 22 | if err != nil { |
| 23 | return false, err |
| 24 | } |
| 25 | |
| 26 | if len(actual) != 2 { |
| 27 | t.Fatalf("Expected 2 servers, got %d", len(actual)) |
| 28 | } |
Ash Wilson | d3532cd | 2014-10-21 14:37:47 -0400 | [diff] [blame] | 29 | th.CheckDeepEquals(t, ServerHerp, actual[0]) |
| 30 | th.CheckDeepEquals(t, ServerDerp, actual[1]) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 31 | |
| 32 | return true, nil |
| 33 | }) |
| 34 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 35 | th.AssertNoErr(t, err) |
Jamie Hannaford | cf00172 | 2014-10-16 12:54:07 +0200 | [diff] [blame] | 36 | |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 37 | if pages != 1 { |
| 38 | t.Errorf("Expected 1 page, saw %d", pages) |
| 39 | } |
| 40 | } |
| 41 | |
Jon Perritt | d27a9c7 | 2015-02-18 11:33:28 -0700 | [diff] [blame] | 42 | func TestListAllServers(t *testing.T) { |
| 43 | th.SetupHTTP() |
| 44 | defer th.TeardownHTTP() |
| 45 | HandleServerListSuccessfully(t) |
| 46 | |
| 47 | allPages, err := List(client.ServiceClient(), ListOpts{}).AllPages() |
| 48 | th.AssertNoErr(t, err) |
| 49 | actual, err := ExtractServers(allPages) |
| 50 | th.AssertNoErr(t, err) |
| 51 | th.CheckDeepEquals(t, ServerHerp, actual[0]) |
| 52 | th.CheckDeepEquals(t, ServerDerp, actual[1]) |
| 53 | } |
| 54 | |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 55 | func TestCreateServer(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 56 | th.SetupHTTP() |
| 57 | defer th.TeardownHTTP() |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 58 | HandleServerCreationSuccessfully(t, SingleServerBody) |
Ash Wilson | 3204d0d | 2014-09-25 10:37:44 -0400 | [diff] [blame] | 59 | |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 60 | actual, err := Create(client.ServiceClient(), CreateOpts{ |
Ash Wilson | 6a310e0 | 2014-09-29 08:24:02 -0400 | [diff] [blame] | 61 | Name: "derp", |
| 62 | ImageRef: "f90f6034-2570-4974-8351-6b49732ef2eb", |
| 63 | FlavorRef: "1", |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 64 | }).Extract() |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 65 | th.AssertNoErr(t, err) |
Ash Wilson | 3204d0d | 2014-09-25 10:37:44 -0400 | [diff] [blame] | 66 | |
Ash Wilson | d3532cd | 2014-10-21 14:37:47 -0400 | [diff] [blame] | 67 | th.CheckDeepEquals(t, ServerDerp, *actual) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | func TestDeleteServer(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 71 | th.SetupHTTP() |
| 72 | defer th.TeardownHTTP() |
Ash Wilson | 664fe33 | 2014-10-21 17:47:49 -0400 | [diff] [blame] | 73 | HandleServerDeletionSuccessfully(t) |
Ash Wilson | aff3627 | 2014-09-25 10:40:05 -0400 | [diff] [blame] | 74 | |
Jamie Hannaford | 34732fe | 2014-10-27 11:29:36 +0100 | [diff] [blame] | 75 | res := Delete(client.ServiceClient(), "asdfasdfasdf") |
| 76 | th.AssertNoErr(t, res.Err) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | func TestGetServer(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 80 | th.SetupHTTP() |
| 81 | defer th.TeardownHTTP() |
Ash Wilson | 189c95c | 2014-10-23 11:41:35 -0400 | [diff] [blame] | 82 | HandleServerGetSuccessfully(t) |
Ash Wilson | a612f1f | 2014-09-25 10:42:40 -0400 | [diff] [blame] | 83 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 84 | client := client.ServiceClient() |
Ash Wilson | d27e0ff | 2014-09-25 11:50:31 -0400 | [diff] [blame] | 85 | actual, err := Get(client, "1234asdf").Extract() |
Ash Wilson | a612f1f | 2014-09-25 10:42:40 -0400 | [diff] [blame] | 86 | if err != nil { |
| 87 | t.Fatalf("Unexpected Get error: %v", err) |
| 88 | } |
| 89 | |
Ash Wilson | d3532cd | 2014-10-21 14:37:47 -0400 | [diff] [blame] | 90 | th.CheckDeepEquals(t, ServerDerp, *actual) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | func TestUpdateServer(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 94 | th.SetupHTTP() |
| 95 | defer th.TeardownHTTP() |
Ash Wilson | 189c95c | 2014-10-23 11:41:35 -0400 | [diff] [blame] | 96 | HandleServerUpdateSuccessfully(t) |
Ash Wilson | 0aac3a8 | 2014-09-25 10:45:03 -0400 | [diff] [blame] | 97 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 98 | client := client.ServiceClient() |
Ash Wilson | dcbc8fb | 2014-09-29 09:05:44 -0400 | [diff] [blame] | 99 | actual, err := Update(client, "1234asdf", UpdateOpts{Name: "new-name"}).Extract() |
Ash Wilson | 0aac3a8 | 2014-09-25 10:45:03 -0400 | [diff] [blame] | 100 | if err != nil { |
| 101 | t.Fatalf("Unexpected Update error: %v", err) |
| 102 | } |
| 103 | |
Ash Wilson | d3532cd | 2014-10-21 14:37:47 -0400 | [diff] [blame] | 104 | th.CheckDeepEquals(t, ServerDerp, *actual) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | func TestChangeServerAdminPassword(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 108 | th.SetupHTTP() |
| 109 | defer th.TeardownHTTP() |
Ash Wilson | 1c1eb88 | 2014-10-21 18:14:31 -0400 | [diff] [blame] | 110 | HandleAdminPasswordChangeSuccessfully(t) |
Ash Wilson | fb99ec7 | 2014-09-25 10:48:51 -0400 | [diff] [blame] | 111 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 112 | res := ChangeAdminPassword(client.ServiceClient(), "1234asdf", "new-password") |
| 113 | th.AssertNoErr(t, res.Err) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | func TestRebootServer(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 117 | th.SetupHTTP() |
| 118 | defer th.TeardownHTTP() |
Ash Wilson | 2295ba5 | 2014-10-21 18:19:28 -0400 | [diff] [blame] | 119 | HandleRebootSuccessfully(t) |
Ash Wilson | 8d368e9 | 2014-09-25 10:49:07 -0400 | [diff] [blame] | 120 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 121 | res := Reboot(client.ServiceClient(), "1234asdf", SoftReboot) |
| 122 | th.AssertNoErr(t, res.Err) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | func TestRebuildServer(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 126 | th.SetupHTTP() |
| 127 | defer th.TeardownHTTP() |
Ash Wilson | acf49c6 | 2014-10-21 18:25:11 -0400 | [diff] [blame] | 128 | HandleRebuildSuccessfully(t, SingleServerBody) |
Ash Wilson | 077f877 | 2014-09-25 10:57:13 -0400 | [diff] [blame] | 129 | |
Jamie Hannaford | 6c9eb60 | 2014-10-16 16:28:07 +0200 | [diff] [blame] | 130 | opts := RebuildOpts{ |
| 131 | Name: "new-name", |
| 132 | AdminPass: "swordfish", |
| 133 | ImageID: "http://104.130.131.164:8774/fcad67a6189847c4aecfa3c81a05783b/images/f90f6034-2570-4974-8351-6b49732ef2eb", |
| 134 | AccessIPv4: "1.2.3.4", |
Ash Wilson | 077f877 | 2014-09-25 10:57:13 -0400 | [diff] [blame] | 135 | } |
| 136 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 137 | actual, err := Rebuild(client.ServiceClient(), "1234asdf", opts).Extract() |
| 138 | th.AssertNoErr(t, err) |
Jamie Hannaford | 6c9eb60 | 2014-10-16 16:28:07 +0200 | [diff] [blame] | 139 | |
Ash Wilson | d3532cd | 2014-10-21 14:37:47 -0400 | [diff] [blame] | 140 | th.CheckDeepEquals(t, ServerDerp, *actual) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | func TestResizeServer(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 144 | th.SetupHTTP() |
| 145 | defer th.TeardownHTTP() |
Ash Wilson | 45181f4 | 2014-09-25 11:00:16 -0400 | [diff] [blame] | 146 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 147 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 148 | th.TestMethod(t, r, "POST") |
| 149 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 150 | th.TestJSONRequest(t, r, `{ "resize": { "flavorRef": "2" } }`) |
Ash Wilson | 45181f4 | 2014-09-25 11:00:16 -0400 | [diff] [blame] | 151 | |
| 152 | w.WriteHeader(http.StatusAccepted) |
| 153 | }) |
| 154 | |
Ash Wilson | 5f7cf18 | 2014-10-23 08:35:24 -0400 | [diff] [blame] | 155 | res := Resize(client.ServiceClient(), "1234asdf", ResizeOpts{FlavorRef: "2"}) |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 156 | th.AssertNoErr(t, res.Err) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | func TestConfirmResize(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 160 | th.SetupHTTP() |
| 161 | defer th.TeardownHTTP() |
Ash Wilson | e2bffd5 | 2014-09-25 11:11:43 -0400 | [diff] [blame] | 162 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 163 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 164 | th.TestMethod(t, r, "POST") |
| 165 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 166 | th.TestJSONRequest(t, r, `{ "confirmResize": null }`) |
Ash Wilson | e2bffd5 | 2014-09-25 11:11:43 -0400 | [diff] [blame] | 167 | |
| 168 | w.WriteHeader(http.StatusNoContent) |
| 169 | }) |
| 170 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 171 | res := ConfirmResize(client.ServiceClient(), "1234asdf") |
| 172 | th.AssertNoErr(t, res.Err) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | func TestRevertResize(t *testing.T) { |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 176 | th.SetupHTTP() |
| 177 | defer th.TeardownHTTP() |
Ash Wilson | 8deb38c | 2014-09-25 11:11:53 -0400 | [diff] [blame] | 178 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 179 | th.Mux.HandleFunc("/servers/1234asdf/action", func(w http.ResponseWriter, r *http.Request) { |
| 180 | th.TestMethod(t, r, "POST") |
| 181 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 182 | th.TestJSONRequest(t, r, `{ "revertResize": null }`) |
Ash Wilson | 8deb38c | 2014-09-25 11:11:53 -0400 | [diff] [blame] | 183 | |
| 184 | w.WriteHeader(http.StatusAccepted) |
| 185 | }) |
| 186 | |
Ash Wilson | e77ffb0 | 2014-10-20 13:10:26 -0400 | [diff] [blame] | 187 | res := RevertResize(client.ServiceClient(), "1234asdf") |
| 188 | th.AssertNoErr(t, res.Err) |
Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame] | 189 | } |
Alex Gaynor | 810d489 | 2014-11-12 15:43:36 -0800 | [diff] [blame] | 190 | |
| 191 | func TestRescue(t *testing.T) { |
| 192 | th.SetupHTTP() |
| 193 | defer th.TeardownHTTP() |
| 194 | |
Alex Gaynor | 6c003d2 | 2014-11-13 13:52:05 -0800 | [diff] [blame] | 195 | HandleServerRescueSuccessfully(t) |
Alex Gaynor | 810d489 | 2014-11-12 15:43:36 -0800 | [diff] [blame] | 196 | |
Alex Gaynor | 40449ed | 2014-11-12 16:28:06 -0800 | [diff] [blame] | 197 | res := Rescue(client.ServiceClient(), "1234asdf", RescueOpts{ |
Alex Gaynor | 3116817 | 2014-11-12 16:27:47 -0800 | [diff] [blame] | 198 | AdminPass: "1234567890", |
Alex Gaynor | 810d489 | 2014-11-12 15:43:36 -0800 | [diff] [blame] | 199 | }) |
| 200 | th.AssertNoErr(t, res.Err) |
Alex Gaynor | 7f3b06e | 2014-11-13 09:54:03 -0800 | [diff] [blame] | 201 | adminPass, _ := res.Extract() |
Alex Gaynor | 0160cff | 2014-11-13 10:17:48 -0800 | [diff] [blame] | 202 | th.AssertEquals(t, "1234567890", adminPass) |
Alex Gaynor | 810d489 | 2014-11-12 15:43:36 -0800 | [diff] [blame] | 203 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 204 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 205 | func TestGetMetadatum(t *testing.T) { |
| 206 | th.SetupHTTP() |
| 207 | defer th.TeardownHTTP() |
| 208 | |
| 209 | HandleMetadatumGetSuccessfully(t) |
| 210 | |
| 211 | expected := map[string]string{"foo": "bar"} |
| 212 | actual, err := Metadatum(client.ServiceClient(), "1234asdf", "foo").Extract() |
| 213 | th.AssertNoErr(t, err) |
| 214 | th.AssertDeepEquals(t, expected, actual) |
| 215 | } |
| 216 | |
| 217 | func TestCreateMetadatum(t *testing.T) { |
| 218 | th.SetupHTTP() |
| 219 | defer th.TeardownHTTP() |
| 220 | |
| 221 | HandleMetadatumCreateSuccessfully(t) |
| 222 | |
| 223 | expected := map[string]string{"foo": "bar"} |
| 224 | actual, err := CreateMetadatum(client.ServiceClient(), "1234asdf", MetadatumOpts{"foo": "bar"}).Extract() |
| 225 | th.AssertNoErr(t, err) |
| 226 | th.AssertDeepEquals(t, expected, actual) |
| 227 | } |
| 228 | |
| 229 | func TestDeleteMetadatum(t *testing.T) { |
| 230 | th.SetupHTTP() |
| 231 | defer th.TeardownHTTP() |
| 232 | |
| 233 | HandleMetadatumDeleteSuccessfully(t) |
| 234 | |
| 235 | err := DeleteMetadatum(client.ServiceClient(), "1234asdf", "foo").ExtractErr() |
| 236 | th.AssertNoErr(t, err) |
| 237 | } |
| 238 | |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 239 | func TestGetMetadata(t *testing.T) { |
| 240 | th.SetupHTTP() |
| 241 | defer th.TeardownHTTP() |
| 242 | |
| 243 | HandleMetadataGetSuccessfully(t) |
| 244 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 245 | expected := map[string]string{"foo": "bar", "this": "that"} |
| 246 | actual, err := Metadata(client.ServiceClient(), "1234asdf").Extract() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 247 | th.AssertNoErr(t, err) |
| 248 | th.AssertDeepEquals(t, expected, actual) |
| 249 | } |
| 250 | |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 251 | func TestResetMetadata(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 252 | th.SetupHTTP() |
| 253 | defer th.TeardownHTTP() |
| 254 | |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 255 | HandleMetadataResetSuccessfully(t) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 256 | |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 257 | expected := map[string]string{"foo": "bar", "this": "that"} |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 258 | actual, err := ResetMetadata(client.ServiceClient(), "1234asdf", MetadataOpts{ |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 259 | "foo": "bar", |
| 260 | "this": "that", |
| 261 | }).Extract() |
| 262 | th.AssertNoErr(t, err) |
| 263 | th.AssertDeepEquals(t, expected, actual) |
| 264 | } |
| 265 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 266 | func TestUpdateMetadata(t *testing.T) { |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 267 | th.SetupHTTP() |
| 268 | defer th.TeardownHTTP() |
| 269 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 270 | HandleMetadataUpdateSuccessfully(t) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 271 | |
| 272 | expected := map[string]string{"foo": "baz", "this": "those"} |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 273 | actual, err := UpdateMetadata(client.ServiceClient(), "1234asdf", MetadataOpts{ |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 274 | "foo": "baz", |
| 275 | "this": "those", |
| 276 | }).Extract() |
| 277 | th.AssertNoErr(t, err) |
| 278 | th.AssertDeepEquals(t, expected, actual) |
| 279 | } |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 280 | |
| 281 | func TestListAddresses(t *testing.T) { |
| 282 | th.SetupHTTP() |
| 283 | defer th.TeardownHTTP() |
| 284 | HandleAddressListSuccessfully(t) |
| 285 | |
| 286 | expected := ListAddressesExpected |
| 287 | pages := 0 |
| 288 | err := ListAddresses(client.ServiceClient(), "asdfasdfasdf").EachPage(func(page pagination.Page) (bool, error) { |
| 289 | pages++ |
| 290 | |
| 291 | actual, err := ExtractAddresses(page) |
| 292 | th.AssertNoErr(t, err) |
| 293 | |
| 294 | if len(actual) != 2 { |
Jon Perritt | 04d073c | 2015-02-19 21:46:23 -0700 | [diff] [blame] | 295 | t.Fatalf("Expected 2 networks, got %d", len(actual)) |
| 296 | } |
| 297 | th.CheckDeepEquals(t, expected, actual) |
| 298 | |
| 299 | return true, nil |
| 300 | }) |
| 301 | th.AssertNoErr(t, err) |
| 302 | th.CheckEquals(t, 1, pages) |
| 303 | } |
| 304 | |
| 305 | func TestListAddressesByNetwork(t *testing.T) { |
| 306 | th.SetupHTTP() |
| 307 | defer th.TeardownHTTP() |
| 308 | HandleNetworkAddressListSuccessfully(t) |
| 309 | |
| 310 | expected := ListNetworkAddressesExpected |
| 311 | pages := 0 |
| 312 | err := ListAddressesByNetwork(client.ServiceClient(), "asdfasdfasdf", "public").EachPage(func(page pagination.Page) (bool, error) { |
| 313 | pages++ |
| 314 | |
| 315 | actual, err := ExtractNetworkAddresses(page) |
| 316 | th.AssertNoErr(t, err) |
| 317 | |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 318 | if len(actual) != 2 { |
| 319 | t.Fatalf("Expected 2 addresses, got %d", len(actual)) |
Jon Perritt | 5cb4948 | 2015-02-19 12:19:58 -0700 | [diff] [blame] | 320 | } |
| 321 | th.CheckDeepEquals(t, expected, actual) |
| 322 | |
| 323 | return true, nil |
| 324 | }) |
| 325 | th.AssertNoErr(t, err) |
| 326 | th.CheckEquals(t, 1, pages) |
| 327 | } |
einarf | 2fc665e | 2015-04-16 20:16:21 +0000 | [diff] [blame^] | 328 | |
| 329 | func TestCreateServerImage(t *testing.T) { |
| 330 | th.SetupHTTP() |
| 331 | defer th.TeardownHTTP() |
| 332 | HandleCreateServerImageSuccessfully(t) |
| 333 | |
| 334 | _, err := CreateServerImage(client.ServiceClient(), "serverimage", CreateServerImageOpts{Name: "test"}).ExtractImageID() |
| 335 | th.AssertNoErr(t, err) |
| 336 | |
| 337 | } |