Skip to content

Commit

Permalink
Merge pull request #7 from ByteInternet/brancher_create_data
Browse files Browse the repository at this point in the history
  • Loading branch information
tdgroot authored Nov 23, 2022
2 parents 01f8bf2 + dda1ac8 commit 742a59b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Service/BrancherApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
class BrancherApp extends AbstractService
{
/**
* Create an brancher app for given parent app.
* Create a brancher app for given parent app.
*
* @param string $app Name of the parent app
* @param array|null $data Extra data to be provided
* @return string Name of the brancher app
* @throws HypernodeApiClientException
* @throws HypernodeApiServerException
*/
public function create(string $app): string
public function create(string $app, ?array $data = null): string
{
$url = sprintf(App::V2_APP_BRANCHER_URL, $app);

$response = $this->client->api->post($url);
$response = $this->client->api->post($url, [], $data ? json_encode($data) : null);

$this->client->maybeThrowApiExceptions($response);

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/Service/BrancherAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ public function testCreateBrancherApp()
$this->assertEquals('johndoe-eph123456', $brancherAppName);
}

public function testCreateBrancherAppWithData()
{
$this->responses->append(
new Response(200, [], json_encode([
'name' => 'johndoe-eph123456',
'parent' => 'johndoe',
'type' => 'brancher',
])),
);

$brancherAppName = $this->client->brancherApp->create(
'johndoe',
['labels' => ['mybranchernode', 'mylabel=myvalue']]
);

$request = $this->responses->getLastRequest();
$this->assertEquals('POST', $request->getMethod());
$this->assertEquals('/v2/app/johndoe/brancher/', $request->getUri());
$this->assertEquals('johndoe-eph123456', $brancherAppName);
$this->assertJson((string)$request->getBody());
$this->assertEquals(
['labels' => ['mybranchernode', 'mylabel=myvalue']],
json_decode((string)$request->getBody(), true)
);
}

public function testCreateBrancherAppRaisesClientExceptions()
{
$badRequestResponse = new Response(400, [], json_encode([
Expand Down

0 comments on commit 742a59b

Please sign in to comment.