Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Jun 19, 2024
1 parent 32534e9 commit 3daa0b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 46 deletions.
17 changes: 12 additions & 5 deletions src/Orchestration/Adapter/DockerAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,18 +479,25 @@ public function run(
'WorkingDir' => $workdir,
'Labels' => (object) $labels,
'Env' => array_values($vars),
'Mounts' => $mountFolder ? [['Type' => 'bind', 'Source' => $mountFolder, 'Target' => '/tmp', 'RW' => true]] : [],
'HostConfig' => [
'Binds' => $volumes,
'CpuQuota' => ! empty($this->cpus) ? floatval($this->cpus) * 100000 : null,
'CpuPeriod' => ! empty($this->cpus) ? 100000 : null,
'Memory' => ! empty($this->memory) ? intval($this->memory) * 1e+6 : null, // Convert into bytes
'MemorySwap' => ! empty($this->swap) ? intval($this->swap) * 1e+6 : null, // Convert into bytes
'CpuQuota' => floatval($this->cpus) * 100000,
'CpuPeriod' => 100000,
'Memory' => intval($this->memory) * 1e+6, // Convert into bytes
'MemorySwap' => intval($this->swap) * 1e+6, // Convert into bytes
'AutoRemove' => $remove,
'NetworkMode' => ! empty($network) ? $network : null,
],
];

if (! empty($mountFolder)) {
$body['HostConfig']['Binds'][] = $mountFolder.':/tmp';
}

$body = array_filter($body, function ($value) {
return ! empty($value);
});

$result = $this->call('http://localhost/containers/create?name='.$name, 'POST', json_encode($body), [
'Content-Type: application/json',
'Content-Length: '.\strlen(\json_encode($body)),
Expand Down
53 changes: 12 additions & 41 deletions tests/Orchestration/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,6 @@ abstract protected static function getAdapterName(): string;
*/
public static $containerID;

public static function setUpBeforeClass(): void
{
$testContainers = [
'TestContainer',
'TestContainerTimeout',
'TestContainerBadBuild',
'UsageStats1',
'UsageStats2',
'TestContainerRM',
'TestContainerRM2',
];

foreach (static::getOrchestration()->list() as $activeContainer) {
if (in_array($activeContainer->getName(), $testContainers)) {
static::getOrchestration()->remove($activeContainer->getName(), true);
}
}

foreach (static::getOrchestration()->listNetworks() as $activeNetwork) {
if ($activeNetwork->getName() === 'TestNetwork') {
static::getOrchestration()->removeNetwork($activeNetwork->getName());
}
}
}

public function setUp(): void
{
}
Expand Down Expand Up @@ -168,17 +143,7 @@ public function testListNetworks(): void
/**
* @depends testCreateNetwork
*/
public function testnetworkConnect(): void
{
$response = static::getOrchestration()->networkConnect('TestContainer', 'TestNetwork');

$this->assertEquals(true, $response);
}

/**
* @depends testCreateNetwork
*/
public function testCreateContainerWithNetwork(): void
public function testNetworkConnect(): void
{
$response = static::getOrchestration()->run(
'appwrite/runtime-for-php:8.0',
Expand All @@ -204,20 +169,26 @@ public function testCreateContainerWithNetwork(): void
);

$this->assertNotEmpty($response);

sleep(1); // wait for container

$response = static::getOrchestration()->networkConnect('TestContainer', 'TestNetwork');

$this->assertEquals(true, $response);
}

/**
* @depends testnetworkConnect
* @depends testNetworkConnect
*/
public function testnetworkDisconnect(): void
public function testNetworkDisconnect(): void
{
$response = static::getOrchestration()->networkDisconnect('TestContainer', 'TestNetwork', true);

$this->assertEquals(true, $response);
}

/**
* @depends testnetworkDisconnect
* @depends testNetworkDisconnect
*/
public function testRemoveNetwork(): void
{
Expand Down Expand Up @@ -272,7 +243,7 @@ public function testExecContainer(): void
*/
$output = '';

$response = static::getOrchestration()->execute(
static::getOrchestration()->execute(
'TestContainer',
[
'php',
Expand All @@ -294,7 +265,7 @@ public function testCheckVolume(): void
{
$output = '';

$response = static::getOrchestration()->execute(
static::getOrchestration()->execute(
'TestContainer',
[
'cat',
Expand Down

0 comments on commit 3daa0b7

Please sign in to comment.