Skip to content

Commit

Permalink
Merge pull request #21 from unikorp/fix/wrong-endpoints-in-cluster-node
Browse files Browse the repository at this point in the history
fix(node): wrong endpoints in cluster node
  • Loading branch information
VEBERArnaud committed Aug 14, 2017
2 parents 5474a81 + 724e899 commit 159267f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
17 changes: 9 additions & 8 deletions src/Node/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,36 @@
class Cluster extends AbstractNode
{
/**
* cluster information
* retrieve cluster status
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function clusterInformation(): ResponseInterface
public function retrieveClusterStatus(): ResponseInterface
{
return $this->get('/cluster');
}

/**
* retrieve cluster status
* add a node
*
* @param \Unikorp\KongAdminApi\Document\Cluster $document
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function retrieveClusterStatus(): ResponseInterface
public function addANode(Document $document): ResponseInterface
{
return $this->get('/cluster/nodes/');
return $this->post('/cluster', $document);
}

/**
* forcibly remove a node
*
* @param string $name
* @param \Unikorp\KongAdminApi\Document\Cluster $document
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function forciblyRemoveANode(string $name, Document $document): ResponseInterface
public function forciblyRemoveANode(Document $document): ResponseInterface
{
return $this->delete(sprintf('/cluster/nodes/%1$s', $name), $document);
return $this->delete('/cluster', $document);
}
}
40 changes: 26 additions & 14 deletions tests/Unit/Node/ClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public function testConstructSetClient()
}

/**
* test cluster information
* test retrieve cluster status
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Node\Cluster::clusterInformation
* @covers \Unikorp\KongAdminApi\Node\Cluster::retrieveClusterStatus
* @covers \Unikorp\KongAdminApi\AbstractNode::get
*/
public function testClusterInformation()
public function testRetrieveClusterStatus()
{
// stub `get http client` method from `client` mock
$this->client->expects($this->once())
Expand All @@ -106,35 +106,47 @@ public function testClusterInformation()
->will($this->returnValue($response));

$node = new Node($this->client);
$node->clusterInformation();
$node->retrieveClusterStatus();
}

/**
* test retrieve cluster status
* test add a node
*
* @return void
*
* @covers \Unikorp\KongAdminApi\Node\Cluster::retrieveClusterStatus
* @covers \Unikorp\KongAdminApi\AbstractNode::get
* @covers \Unikorp\KongAdminApi\Node\Cluster::addANode
* @covers \Unikorp\KongAdminApi\AbstractNode::post
*/
public function testRetrieveClusterStatus()
public function testAddANode()
{
// stub `get http client` method from `client` mock
$this->client->expects($this->once())
->method('getHttpClient')
->will($this->returnValue($this->httpClient));

// mock `document`
$document = $this->createMock('\Unikorp\KongAdminApi\Document\Cluster');

// mock `response`
$response = $this->createMock('\GuzzleHttp\Psr7\Response');

// stub `get` method from `http client` mock
// stub `to json` method from `document` mock
$document->expects($this->once())
->method('toJson')
->will($this->returnValue('{"test":true}'));

// stub `delete` method from `http client` mock
$this->httpClient->expects($this->once())
->method('get')
->with($this->equalTo('/cluster/nodes/'))
->method('post')
->with(
$this->equalTo('/cluster'),
$this->equalTo(['Content-Type' => 'application/json']),
$this->equalTo('{"test":true}')
)
->will($this->returnValue($response));

$node = new Node($this->client);
$node->retrieveClusterStatus();
$node->addANode($document);
}

/**
Expand Down Expand Up @@ -167,13 +179,13 @@ public function testForciblyRemoveANode()
$this->httpClient->expects($this->once())
->method('delete')
->with(
$this->equalTo('/cluster/nodes/test-cluster'),
$this->equalTo('/cluster'),
$this->equalTo(['Content-Type' => 'application/json']),
$this->equalTo('{"test":true}')
)
->will($this->returnValue($response));

$node = new Node($this->client);
$node->forciblyRemoveANode('test-cluster', $document);
$node->forciblyRemoveANode($document);
}
}

0 comments on commit 159267f

Please sign in to comment.