Jamie Hannaford | fba65af | 2014-11-03 10:32:37 +0100 | [diff] [blame] | 1 | package lbs |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 2 | |
| 3 | import ( |
| 4 | "testing" |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 5 | "time" |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 6 | |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud/pagination" |
Jamie Hannaford | 89ebfc2 | 2014-11-03 16:27:47 +0100 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/rackspace/lb/v1/nodes" |
Jamie Hannaford | 6bc93aa | 2014-11-06 12:37:52 +0100 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/rackspace/lb/v1/sessions" |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/rackspace/lb/v1/throttle" |
Jamie Hannaford | 1c81731 | 2014-11-04 10:56:58 +0100 | [diff] [blame] | 12 | "github.com/rackspace/gophercloud/rackspace/lb/v1/vips" |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 13 | th "github.com/rackspace/gophercloud/testhelper" |
| 14 | "github.com/rackspace/gophercloud/testhelper/client" |
| 15 | ) |
| 16 | |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 17 | const ( |
| 18 | id1 = 12345 |
| 19 | id2 = 67890 |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 20 | ts1 = "2010-11-30T03:23:42Z" |
| 21 | ts2 = "2010-11-30T03:23:44Z" |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 22 | ) |
| 23 | |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 24 | func toTime(t *testing.T, str string) time.Time { |
| 25 | ts, err := time.Parse(time.RFC3339, str) |
| 26 | if err != nil { |
| 27 | t.Fatalf("Could not parse time: %s", err.Error()) |
| 28 | } |
| 29 | return ts |
| 30 | } |
| 31 | |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 32 | func TestList(t *testing.T) { |
| 33 | th.SetupHTTP() |
| 34 | defer th.TeardownHTTP() |
| 35 | |
| 36 | mockListLBResponse(t) |
| 37 | |
| 38 | count := 0 |
| 39 | |
| 40 | err := List(client.ServiceClient(), ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { |
| 41 | count++ |
| 42 | actual, err := ExtractLBs(page) |
| 43 | th.AssertNoErr(t, err) |
| 44 | |
| 45 | expected := []LoadBalancer{ |
| 46 | LoadBalancer{ |
| 47 | Name: "lb-site1", |
| 48 | ID: 71, |
| 49 | Protocol: "HTTP", |
| 50 | Port: 80, |
Jamie Hannaford | 4633628 | 2014-11-04 14:48:20 +0100 | [diff] [blame] | 51 | Algorithm: "RANDOM", |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 52 | Status: ACTIVE, |
| 53 | NodeCount: 3, |
Jamie Hannaford | 1c81731 | 2014-11-04 10:56:58 +0100 | [diff] [blame] | 54 | VIPs: []vips.VIP{ |
| 55 | vips.VIP{ |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 56 | ID: 403, |
| 57 | Address: "206.55.130.1", |
| 58 | Type: "PUBLIC", |
| 59 | Version: "IPV4", |
| 60 | }, |
| 61 | }, |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 62 | Created: Datetime{Time: toTime(t, ts1)}, |
| 63 | Updated: Datetime{Time: toTime(t, ts2)}, |
| 64 | }, |
| 65 | LoadBalancer{ |
| 66 | ID: 72, |
| 67 | Name: "lb-site2", |
| 68 | Created: Datetime{Time: toTime(t, "2011-11-30T03:23:42Z")}, |
| 69 | Updated: Datetime{Time: toTime(t, "2011-11-30T03:23:44Z")}, |
| 70 | }, |
| 71 | LoadBalancer{ |
| 72 | ID: 73, |
| 73 | Name: "lb-site3", |
| 74 | Created: Datetime{Time: toTime(t, "2012-11-30T03:23:42Z")}, |
| 75 | Updated: Datetime{Time: toTime(t, "2012-11-30T03:23:44Z")}, |
Jamie Hannaford | 186d4e2 | 2014-10-31 12:26:11 +0100 | [diff] [blame] | 76 | }, |
| 77 | } |
| 78 | |
| 79 | th.CheckDeepEquals(t, expected, actual) |
| 80 | |
| 81 | return true, nil |
| 82 | }) |
| 83 | |
| 84 | th.AssertNoErr(t, err) |
| 85 | th.AssertEquals(t, 1, count) |
| 86 | } |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 87 | |
| 88 | func TestCreate(t *testing.T) { |
| 89 | th.SetupHTTP() |
| 90 | defer th.TeardownHTTP() |
| 91 | |
| 92 | mockCreateLBResponse(t) |
| 93 | |
| 94 | opts := CreateOpts{ |
| 95 | Name: "a-new-loadbalancer", |
| 96 | Port: 80, |
| 97 | Protocol: "HTTP", |
Jamie Hannaford | 1c81731 | 2014-11-04 10:56:58 +0100 | [diff] [blame] | 98 | VIPs: []vips.VIP{ |
| 99 | vips.VIP{ID: 2341}, |
| 100 | vips.VIP{ID: 900001}, |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 101 | }, |
Jamie Hannaford | 89ebfc2 | 2014-11-03 16:27:47 +0100 | [diff] [blame] | 102 | Nodes: []nodes.Node{ |
| 103 | nodes.Node{Address: "10.1.1.1", Port: 80, Condition: "ENABLED"}, |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 104 | }, |
| 105 | } |
| 106 | |
| 107 | lb, err := Create(client.ServiceClient(), opts).Extract() |
| 108 | th.AssertNoErr(t, err) |
| 109 | |
| 110 | expected := &LoadBalancer{ |
| 111 | Name: "a-new-loadbalancer", |
| 112 | ID: 144, |
| 113 | Protocol: "HTTP", |
| 114 | HalfClosed: false, |
| 115 | Port: 83, |
Jamie Hannaford | 4633628 | 2014-11-04 14:48:20 +0100 | [diff] [blame] | 116 | Algorithm: "RANDOM", |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 117 | Status: BUILD, |
| 118 | Timeout: 30, |
| 119 | Cluster: Cluster{Name: "ztm-n01.staging1.lbaas.rackspace.net"}, |
Jamie Hannaford | 89ebfc2 | 2014-11-03 16:27:47 +0100 | [diff] [blame] | 120 | Nodes: []nodes.Node{ |
| 121 | nodes.Node{ |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 122 | Address: "10.1.1.1", |
| 123 | ID: 653, |
| 124 | Port: 80, |
| 125 | Status: "ONLINE", |
| 126 | Condition: "ENABLED", |
| 127 | Weight: 1, |
| 128 | }, |
| 129 | }, |
Jamie Hannaford | 1c81731 | 2014-11-04 10:56:58 +0100 | [diff] [blame] | 130 | VIPs: []vips.VIP{ |
| 131 | vips.VIP{ |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 132 | ID: 39, |
| 133 | Address: "206.10.10.210", |
Jamie Hannaford | d56375d | 2014-11-05 12:38:04 +0100 | [diff] [blame] | 134 | Type: vips.PUBLIC, |
| 135 | Version: vips.IPV4, |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 136 | }, |
Jamie Hannaford | 1c81731 | 2014-11-04 10:56:58 +0100 | [diff] [blame] | 137 | vips.VIP{ |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 138 | ID: 900001, |
| 139 | Address: "2001:4801:79f1:0002:711b:be4c:0000:0021", |
Jamie Hannaford | d56375d | 2014-11-05 12:38:04 +0100 | [diff] [blame] | 140 | Type: vips.PUBLIC, |
| 141 | Version: vips.IPV6, |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 142 | }, |
| 143 | }, |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 144 | Created: Datetime{Time: toTime(t, ts1)}, |
| 145 | Updated: Datetime{Time: toTime(t, ts2)}, |
Jamie Hannaford | e09b682 | 2014-10-31 15:33:57 +0100 | [diff] [blame] | 146 | ConnectionLogging: ConnectionLogging{Enabled: false}, |
| 147 | } |
| 148 | |
| 149 | th.AssertDeepEquals(t, expected, lb) |
| 150 | } |
Jamie Hannaford | 1c26033 | 2014-10-31 15:57:22 +0100 | [diff] [blame] | 151 | |
Jamie Hannaford | fcd2259 | 2014-10-31 16:15:34 +0100 | [diff] [blame] | 152 | func TestBulkDelete(t *testing.T) { |
Jamie Hannaford | 1c26033 | 2014-10-31 15:57:22 +0100 | [diff] [blame] | 153 | th.SetupHTTP() |
| 154 | defer th.TeardownHTTP() |
| 155 | |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 156 | ids := []int{id1, id2} |
Jamie Hannaford | 1c26033 | 2014-10-31 15:57:22 +0100 | [diff] [blame] | 157 | |
Jamie Hannaford | 5f95e6a | 2014-10-31 16:13:44 +0100 | [diff] [blame] | 158 | mockBatchDeleteLBResponse(t, ids) |
| 159 | |
| 160 | err := BulkDelete(client.ServiceClient(), ids).ExtractErr() |
| 161 | th.AssertNoErr(t, err) |
| 162 | } |
| 163 | |
Jamie Hannaford | fcd2259 | 2014-10-31 16:15:34 +0100 | [diff] [blame] | 164 | func TestDelete(t *testing.T) { |
Jamie Hannaford | 5f95e6a | 2014-10-31 16:13:44 +0100 | [diff] [blame] | 165 | th.SetupHTTP() |
| 166 | defer th.TeardownHTTP() |
| 167 | |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 168 | mockDeleteLBResponse(t, id1) |
Jamie Hannaford | 5f95e6a | 2014-10-31 16:13:44 +0100 | [diff] [blame] | 169 | |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 170 | err := Delete(client.ServiceClient(), id1).ExtractErr() |
Jamie Hannaford | 1c26033 | 2014-10-31 15:57:22 +0100 | [diff] [blame] | 171 | th.AssertNoErr(t, err) |
| 172 | } |
Jamie Hannaford | fcd2259 | 2014-10-31 16:15:34 +0100 | [diff] [blame] | 173 | |
| 174 | func TestGet(t *testing.T) { |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 175 | th.SetupHTTP() |
| 176 | defer th.TeardownHTTP() |
Jamie Hannaford | fcd2259 | 2014-10-31 16:15:34 +0100 | [diff] [blame] | 177 | |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 178 | mockGetLBResponse(t, id1) |
| 179 | |
| 180 | lb, err := Get(client.ServiceClient(), id1).Extract() |
| 181 | |
| 182 | expected := &LoadBalancer{ |
| 183 | Name: "sample-loadbalancer", |
| 184 | ID: 2000, |
| 185 | Protocol: "HTTP", |
| 186 | Port: 80, |
Jamie Hannaford | 4633628 | 2014-11-04 14:48:20 +0100 | [diff] [blame] | 187 | Algorithm: "RANDOM", |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 188 | Status: ACTIVE, |
| 189 | Timeout: 30, |
| 190 | ConnectionLogging: ConnectionLogging{Enabled: true}, |
Jamie Hannaford | 1c81731 | 2014-11-04 10:56:58 +0100 | [diff] [blame] | 191 | VIPs: []vips.VIP{ |
| 192 | vips.VIP{ |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 193 | ID: 1000, |
| 194 | Address: "206.10.10.210", |
| 195 | Type: "PUBLIC", |
| 196 | Version: "IPV4", |
| 197 | }, |
| 198 | }, |
Jamie Hannaford | 89ebfc2 | 2014-11-03 16:27:47 +0100 | [diff] [blame] | 199 | Nodes: []nodes.Node{ |
| 200 | nodes.Node{ |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 201 | Address: "10.1.1.1", |
| 202 | ID: 1041, |
| 203 | Port: 80, |
| 204 | Status: "ONLINE", |
| 205 | Condition: "ENABLED", |
| 206 | }, |
Jamie Hannaford | 89ebfc2 | 2014-11-03 16:27:47 +0100 | [diff] [blame] | 207 | nodes.Node{ |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 208 | Address: "10.1.1.2", |
| 209 | ID: 1411, |
| 210 | Port: 80, |
| 211 | Status: "ONLINE", |
| 212 | Condition: "ENABLED", |
| 213 | }, |
| 214 | }, |
Jamie Hannaford | 6bc93aa | 2014-11-06 12:37:52 +0100 | [diff] [blame] | 215 | SessionPersistence: sessions.SessionPersistence{Type: "HTTP_COOKIE"}, |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 216 | ConnectionThrottle: throttle.ConnectionThrottle{MaxConnections: 100}, |
| 217 | Cluster: Cluster{Name: "c1.dfw1"}, |
Jamie Hannaford | 4d398ff | 2014-11-14 11:03:00 +0100 | [diff] [blame] | 218 | Created: Datetime{Time: toTime(t, ts1)}, |
| 219 | Updated: Datetime{Time: toTime(t, ts2)}, |
Jamie Hannaford | 07c0696 | 2014-10-31 16:42:03 +0100 | [diff] [blame] | 220 | SourceAddrs: SourceAddrs{ |
| 221 | IPv4Public: "10.12.99.28", |
| 222 | IPv4Private: "10.0.0.0", |
| 223 | IPv6Public: "2001:4801:79f1:1::1/64", |
| 224 | }, |
| 225 | } |
| 226 | |
| 227 | th.AssertDeepEquals(t, expected, lb) |
| 228 | th.AssertNoErr(t, err) |
Jamie Hannaford | fcd2259 | 2014-10-31 16:15:34 +0100 | [diff] [blame] | 229 | } |
Jamie Hannaford | 76fcc83 | 2014-10-31 16:56:50 +0100 | [diff] [blame] | 230 | |
| 231 | func TestUpdate(t *testing.T) { |
| 232 | th.SetupHTTP() |
| 233 | defer th.TeardownHTTP() |
| 234 | |
| 235 | mockUpdateLBResponse(t, id1) |
| 236 | |
| 237 | opts := UpdateOpts{ |
| 238 | Name: "a-new-loadbalancer", |
| 239 | Protocol: "TCP", |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 240 | HalfClosed: gophercloud.Enabled, |
Jamie Hannaford | 4633628 | 2014-11-04 14:48:20 +0100 | [diff] [blame] | 241 | Algorithm: "RANDOM", |
Jamie Hannaford | 76fcc83 | 2014-10-31 16:56:50 +0100 | [diff] [blame] | 242 | Port: 8080, |
| 243 | Timeout: 100, |
Jamie Hannaford | cfe2f28 | 2014-11-07 15:11:21 +0100 | [diff] [blame] | 244 | HTTPSRedirect: gophercloud.Disabled, |
Jamie Hannaford | 76fcc83 | 2014-10-31 16:56:50 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | err := Update(client.ServiceClient(), id1, opts).ExtractErr() |
| 248 | th.AssertNoErr(t, err) |
| 249 | } |
Jamie Hannaford | 4ab9aea | 2014-11-04 14:38:06 +0100 | [diff] [blame] | 250 | |
| 251 | func TestListProtocols(t *testing.T) { |
| 252 | th.SetupHTTP() |
| 253 | defer th.TeardownHTTP() |
| 254 | |
| 255 | mockListProtocolsResponse(t) |
| 256 | |
| 257 | count := 0 |
| 258 | |
| 259 | err := ListProtocols(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 260 | count++ |
| 261 | actual, err := ExtractProtocols(page) |
| 262 | th.AssertNoErr(t, err) |
| 263 | |
| 264 | expected := []Protocol{ |
| 265 | Protocol{Name: "DNS_TCP", Port: 53}, |
| 266 | Protocol{Name: "DNS_UDP", Port: 53}, |
| 267 | Protocol{Name: "FTP", Port: 21}, |
| 268 | Protocol{Name: "HTTP", Port: 80}, |
| 269 | Protocol{Name: "HTTPS", Port: 443}, |
| 270 | Protocol{Name: "IMAPS", Port: 993}, |
| 271 | Protocol{Name: "IMAPv4", Port: 143}, |
| 272 | } |
| 273 | |
| 274 | th.CheckDeepEquals(t, expected[0:7], actual) |
| 275 | |
| 276 | return true, nil |
| 277 | }) |
| 278 | |
| 279 | th.AssertNoErr(t, err) |
| 280 | th.AssertEquals(t, 1, count) |
| 281 | } |
Jamie Hannaford | 4633628 | 2014-11-04 14:48:20 +0100 | [diff] [blame] | 282 | |
| 283 | func TestListAlgorithms(t *testing.T) { |
| 284 | th.SetupHTTP() |
| 285 | defer th.TeardownHTTP() |
| 286 | |
| 287 | mockListAlgorithmsResponse(t) |
| 288 | |
| 289 | count := 0 |
| 290 | |
| 291 | err := ListAlgorithms(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 292 | count++ |
| 293 | actual, err := ExtractAlgorithms(page) |
| 294 | th.AssertNoErr(t, err) |
| 295 | |
| 296 | expected := []Algorithm{ |
| 297 | Algorithm{Name: "LEAST_CONNECTIONS"}, |
| 298 | Algorithm{Name: "RANDOM"}, |
| 299 | Algorithm{Name: "ROUND_ROBIN"}, |
| 300 | Algorithm{Name: "WEIGHTED_LEAST_CONNECTIONS"}, |
| 301 | Algorithm{Name: "WEIGHTED_ROUND_ROBIN"}, |
| 302 | } |
| 303 | |
| 304 | th.CheckDeepEquals(t, expected, actual) |
| 305 | |
| 306 | return true, nil |
| 307 | }) |
| 308 | |
| 309 | th.AssertNoErr(t, err) |
| 310 | th.AssertEquals(t, 1, count) |
| 311 | } |
Jamie Hannaford | d78bb35 | 2014-11-07 16:36:09 +0100 | [diff] [blame] | 312 | |
| 313 | func TestIsLoggingEnabled(t *testing.T) { |
| 314 | th.SetupHTTP() |
| 315 | defer th.TeardownHTTP() |
| 316 | |
| 317 | mockGetLoggingResponse(t, id1) |
| 318 | |
| 319 | res, err := IsLoggingEnabled(client.ServiceClient(), id1) |
| 320 | th.AssertNoErr(t, err) |
| 321 | th.AssertEquals(t, true, res) |
| 322 | } |
Jamie Hannaford | da45b42 | 2014-11-10 11:00:38 +0100 | [diff] [blame] | 323 | |
Jamie Hannaford | 20b7588 | 2014-11-10 13:39:51 +0100 | [diff] [blame] | 324 | func TestEnablingLogging(t *testing.T) { |
| 325 | th.SetupHTTP() |
| 326 | defer th.TeardownHTTP() |
| 327 | |
| 328 | mockEnableLoggingResponse(t, id1) |
| 329 | |
| 330 | err := EnableLogging(client.ServiceClient(), id1).ExtractErr() |
| 331 | th.AssertNoErr(t, err) |
| 332 | } |
| 333 | |
| 334 | func TestDisablingLogging(t *testing.T) { |
| 335 | th.SetupHTTP() |
| 336 | defer th.TeardownHTTP() |
| 337 | |
| 338 | mockDisableLoggingResponse(t, id1) |
| 339 | |
| 340 | err := DisableLogging(client.ServiceClient(), id1).ExtractErr() |
| 341 | th.AssertNoErr(t, err) |
| 342 | } |
| 343 | |
Jamie Hannaford | da45b42 | 2014-11-10 11:00:38 +0100 | [diff] [blame] | 344 | func TestGetErrorPage(t *testing.T) { |
| 345 | th.SetupHTTP() |
| 346 | defer th.TeardownHTTP() |
| 347 | |
| 348 | mockGetErrorPageResponse(t, id1) |
| 349 | |
| 350 | content, err := GetErrorPage(client.ServiceClient(), id1).Extract() |
| 351 | th.AssertNoErr(t, err) |
| 352 | |
| 353 | expected := &ErrorPage{Content: "<html>DEFAULT ERROR PAGE</html>"} |
| 354 | th.AssertDeepEquals(t, expected, content) |
| 355 | } |
| 356 | |
| 357 | func TestSetErrorPage(t *testing.T) { |
| 358 | th.SetupHTTP() |
| 359 | defer th.TeardownHTTP() |
| 360 | |
| 361 | mockSetErrorPageResponse(t, id1) |
| 362 | |
| 363 | html := "<html>New error page</html>" |
| 364 | content, err := SetErrorPage(client.ServiceClient(), id1, html).Extract() |
| 365 | th.AssertNoErr(t, err) |
| 366 | |
| 367 | expected := &ErrorPage{Content: html} |
| 368 | th.AssertDeepEquals(t, expected, content) |
| 369 | } |
| 370 | |
| 371 | func TestDeleteErrorPage(t *testing.T) { |
| 372 | th.SetupHTTP() |
| 373 | defer th.TeardownHTTP() |
| 374 | |
| 375 | mockDeleteErrorPageResponse(t, id1) |
| 376 | |
| 377 | err := DeleteErrorPage(client.ServiceClient(), id1).ExtractErr() |
| 378 | th.AssertNoErr(t, err) |
| 379 | } |
Jamie Hannaford | 3da6528 | 2014-11-10 11:36:16 +0100 | [diff] [blame] | 380 | |
| 381 | func TestGetStats(t *testing.T) { |
| 382 | th.SetupHTTP() |
| 383 | defer th.TeardownHTTP() |
| 384 | |
| 385 | mockGetStatsResponse(t, id1) |
| 386 | |
| 387 | content, err := GetStats(client.ServiceClient(), id1).Extract() |
| 388 | th.AssertNoErr(t, err) |
| 389 | |
| 390 | expected := &Stats{ |
| 391 | ConnectTimeout: 10, |
| 392 | ConnectError: 20, |
| 393 | ConnectFailure: 30, |
| 394 | DataTimedOut: 40, |
| 395 | KeepAliveTimedOut: 50, |
| 396 | MaxConnections: 60, |
| 397 | CurrentConnections: 40, |
| 398 | SSLConnectTimeout: 10, |
| 399 | SSLConnectError: 20, |
| 400 | SSLConnectFailure: 30, |
| 401 | SSLDataTimedOut: 40, |
| 402 | SSLKeepAliveTimedOut: 50, |
| 403 | SSLMaxConnections: 60, |
| 404 | SSLCurrentConnections: 40, |
| 405 | } |
| 406 | th.AssertDeepEquals(t, expected, content) |
| 407 | } |
Jamie Hannaford | 20b7588 | 2014-11-10 13:39:51 +0100 | [diff] [blame] | 408 | |
| 409 | func TestIsCached(t *testing.T) { |
| 410 | th.SetupHTTP() |
| 411 | defer th.TeardownHTTP() |
| 412 | |
| 413 | mockGetCachingResponse(t, id1) |
| 414 | |
| 415 | res, err := IsContentCached(client.ServiceClient(), id1) |
| 416 | th.AssertNoErr(t, err) |
| 417 | th.AssertEquals(t, true, res) |
| 418 | } |
| 419 | |
| 420 | func TestEnablingCaching(t *testing.T) { |
| 421 | th.SetupHTTP() |
| 422 | defer th.TeardownHTTP() |
| 423 | |
| 424 | mockEnableCachingResponse(t, id1) |
| 425 | |
| 426 | err := EnableCaching(client.ServiceClient(), id1).ExtractErr() |
| 427 | th.AssertNoErr(t, err) |
| 428 | } |
| 429 | |
| 430 | func TestDisablingCaching(t *testing.T) { |
| 431 | th.SetupHTTP() |
| 432 | defer th.TeardownHTTP() |
| 433 | |
| 434 | mockDisableCachingResponse(t, id1) |
| 435 | |
| 436 | err := DisableCaching(client.ServiceClient(), id1).ExtractErr() |
| 437 | th.AssertNoErr(t, err) |
| 438 | } |