Page MenuHomeDevCentral

No OneTemporary

diff --git a/DevCentralDockerTest.php b/DevCentralDockerTest.php
index e200639..d5214e7 100644
--- a/DevCentralDockerTest.php
+++ b/DevCentralDockerTest.php
@@ -1,38 +1,42 @@
<?php
require_once 'utils/DockerContainer.php';
class DevCentralDockerTest extends PHPUnit_Framework_TestCase {
private $container;
const DOCKER_CONTAINER = 'devcentral';
protected function setUp () {
if (!getenv('DOCKER_ACCESS')) {
$this->markTestSkipped("No access to Docker engine.");
}
$this->container = new DockerContainer(getenv('DOCKER_HOST'), self::DOCKER_CONTAINER);
}
public function testInitialized () {
- //TODO: test if .initialized file exists
- $this->markTestIncomplete("This test will have to be implemented after container update.");
+ $file = $this->container->exec("ls /opt/phabricator/.initialized");
+
+ $this->assertSame(
+ "/opt/phabricator/.initialized", $file,
+ ".initialized file is missing: that could mean the whole /usr/local/bin/setup-phabricator didn't run."
+ );
}
public function testProcesses () {
$processes = $this->container->exec("ps auxw");
$expectedProcesses = [
'nginx: master process',
'nginx: worker process',
'php-fpm: master process',
'PhabricatorTaskmasterDaemon',
'PhabricatorBot',
];
foreach ($expectedProcesses as $expectedProcess) {
$this->assertContains($expectedProcess, $processes, "The process $expectedProcess isn't currently launched.");
}
}
}
diff --git a/utils/DockerContainer.php b/utils/DockerContainer.php
index b69c43f..9f0d3da 100644
--- a/utils/DockerContainer.php
+++ b/utils/DockerContainer.php
@@ -1,53 +1,54 @@
<?php
class DockerContainer {
private $host;
private $container;
/**
* Initializes a new instance of the DockerContainer class
*
* @param string $host hostname
* @param string $container container name
*/
public function __construct ($host, $container) {
if (!self::isValidHostname($host)) {
throw new ArgumentException("Invalid hostname.");
}
if (!self::isValidContainerName($container)) {
throw new ArgumentException("Invalid container name.");
}
$this->host = $host;
$this->container = $container;
}
/**
* Determines if a hostname is valid
*
* @return bool true if the specified name is valid; otherwise, false
*/
public static function isValidHostname ($host) {
return (bool)preg_match('/^[A-Za-z0-9\-\.]+$/', $host);
}
/**
* Determines if a container name is valid
*
* @return bool true if the specified name is valid; otherwise, false
*/
public static function isValidContainerName ($name) {
//Source: https://github.com/ajhager/docker/commit/f63cdf0260cf6287d28a589a79d3f947def6a569
return (bool)preg_match('@^/?[a-zA-Z0-9_-]+$@', $name);
}
/**
* Executes the specified command in the container
*
* @param string $command the command to run
* @return string the command output
*/
public function exec ($command) {
- return `ssh $this->host docker exec $this->container $command`;
+ $output = `ssh $this->host docker exec $this->container $command`;
+ return trim($output);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 01:17 (17 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259315
Default Alt Text
(3 KB)

Event Timeline