Skip to content

Commit 344016d

Browse files
author
Jamie Hannaford
committed
Implement into service and refactor tests
1 parent b7522f3 commit 344016d

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

lib/OpenCloud/LoadBalancer/Service.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use OpenCloud\Common\Log\Logger;
2121
use OpenCloud\Common\Service\NovaService;
22+
use OpenCloud\LoadBalancer\Collection\LoadBalancerIterator;
2223

2324
/**
2425
* Class that encapsulates the Rackspace Cloud Load Balancers service
@@ -51,11 +52,20 @@ public function loadBalancer($id = null)
5152
*/
5253
public function loadBalancerList($detail = true, array $filter = array())
5354
{
55+
$options = $this->makeResourceIteratorOptions($this->resolveResourceClass('LoadBalancer'));
56+
57+
if (isset($filter['limit'])) {
58+
$options['limit.page'] = $filter['limit'];
59+
unset($filter['limit']);
60+
}
61+
5462
$url = $this->getUrl();
5563
$url->addPath(Resource\LoadBalancer::resourceName());
5664
$url->setQuery($filter);
5765

58-
return $this->resourceList('LoadBalancer', $url);
66+
$options += array('baseUrl' => $url, 'key.marker' => 'id');
67+
68+
return LoadBalancerIterator::factory($this, $options);
5969
}
6070

6171
/**

tests/OpenCloud/Tests/LoadBalancer/ServiceTest.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@
2727

2828
namespace OpenCloud\Tests\LoadBalancer;
2929

30-
class ServiceTest extends \OpenCloud\Tests\OpenCloudTestCase
31-
{
32-
private $service;
33-
34-
public function setupObjects()
35-
{
36-
$this->service = $this->getClient()->loadBalancerService('cloudLoadBalancers', 'DFW', 'publicURL');
37-
}
30+
use Guzzle\Http\Message\Response;
31+
use Guzzle\Plugin\Mock\MockPlugin;
32+
use OpenCloud\Rackspace;
33+
use OpenCloud\Tests\MockSubscriber;
3834

35+
class ServiceTest extends LoadBalancerTestCase
36+
{
3937
public function test__construct()
4038
{
4139
$this->assertInstanceOf(
@@ -52,12 +50,36 @@ public function testLoadBalancer()
5250
);
5351
}
5452

55-
public function testLoadBalancerList()
53+
public function test_Listing_Load_Balancers()
5654
{
57-
$this->assertInstanceOf(
58-
self::COLLECTION_CLASS,
59-
$this->service->loadBalancerList()
60-
);
55+
// Load JSON HTTP data
56+
$authData = file_get_contents($this->getTestFilePath('Auth', './'));
57+
$data1 = file_get_contents($this->getTestFilePath('LoadBalancers1'));
58+
$data2 = file_get_contents($this->getTestFilePath('LoadBalancers2'));
59+
$data3 = file_get_contents($this->getTestFilePath('LoadBalancers3'));
60+
61+
// Populate mock response queue
62+
$mock = new MockPlugin();
63+
$mock->addResponse(Response::fromMessage($authData))
64+
->addResponse(Response::fromMessage($data1))
65+
->addResponse(Response::fromMessage($data2))
66+
->addResponse(Response::fromMessage($data3));
67+
68+
// We need to define our own setup because *jazz hands*
69+
$client = $this->newClient();
70+
$client->addSubscriber($mock);
71+
$service = $client->loadBalancerService(null, 'IAD');
72+
73+
// Ensure that a series of paginated calls return a holistic collection
74+
$lbs = $service->loadBalancerList(false, array('limit' => 2));
75+
$ids = array();
76+
foreach ($lbs as $lb) {
77+
$ids[] = $lb->id;
78+
}
79+
80+
// Check our assumptions
81+
$this->isCollection($lbs);
82+
$this->assertEquals($ids, array(1,2,3,4,5));
6183
}
6284

6385
public function testBillableLoadBalancer()

tests/OpenCloud/Tests/OpenCloudTestCase.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,10 @@ abstract class OpenCloudTestCase extends \PHPUnit_Framework_TestCase
3838

3939
public function newClient()
4040
{
41-
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
41+
return new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
4242
'username' => 'foo',
4343
'apiKey' => 'bar'
4444
));
45-
46-
$client->addSubscriber(new MockSubscriber());
47-
//$client->addSubscriber(LogPlugin::getDebugPlugin());
48-
49-
$client->authenticate();
50-
51-
return $client;
5245
}
5346

5447
public function getClient()
@@ -59,6 +52,10 @@ public function getClient()
5952
public function setUp()
6053
{
6154
$this->client = $this->newClient();
55+
56+
$this->client->addSubscriber(new MockSubscriber());
57+
$this->client->authenticate();
58+
6259
$this->setupObjects();
6360
$this->handleMockSubscribers();
6461
}

0 commit comments

Comments
 (0)