Page MenuHomeDevCentral

D62.diff
No OneTemporary

D62.diff

diff --git a/tests/prod-environment-behaves-correctly/DevCentralDockerTest.php b/tests/prod-environment-behaves-correctly/DevCentralDockerTest.php
new file mode 100644
--- /dev/null
+++ b/tests/prod-environment-behaves-correctly/DevCentralDockerTest.php
@@ -0,0 +1,38 @@
+<?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.");
+ }
+
+ 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);
+ }
+ }
+}
diff --git a/tests/prod-environment-behaves-correctly/DevCentralTest.php b/tests/prod-environment-behaves-correctly/DevCentralTest.php
new file mode 100644
--- /dev/null
+++ b/tests/prod-environment-behaves-correctly/DevCentralTest.php
@@ -0,0 +1,17 @@
+<?php
+
+require_once 'traits/assertHttp.php';
+
+class DevCentralTest extends PHPUnit_Framework_TestCase {
+ use assertHttp;
+
+ public function testWebsiteIsUp () {
+ $this->assertHttpResponseCode(200, 'http://devcentral.nasqueron.org', 'DevCentral looks down.');
+ $this->assertHttpResponseCode(200, 'https://devcentral.nasqueron.org', "DevCentral HTTPS issue.");
+ $this->assertHttpResponseCode(500, 'http://phabricator-files-for-devcentral-nasqueron.spacetechnology.net', "DevCentral alternative domain should return a 500 error code for homepage. Check phabricator.base-uri isn't empty.");
+ }
+
+ public function testAphlictIsUp () {
+ $this->assertHttpResponseCode(405, 'http://dwellers.nasqueron.org:22281/', 'Aphlict server seems down, does aphlict container is launched in Docker engine?');
+ }
+}
diff --git a/tests/prod-environment-behaves-correctly/EtherpadTest.php b/tests/prod-environment-behaves-correctly/EtherpadTest.php
--- a/tests/prod-environment-behaves-correctly/EtherpadTest.php
+++ b/tests/prod-environment-behaves-correctly/EtherpadTest.php
@@ -1,6 +1,6 @@
<?php
-require 'traits/assertHttp.php';
+require_once 'traits/assertHttp.php';
class EtherpadTest extends PHPUnit_Framework_TestCase {
use assertHttp;
diff --git a/tests/prod-environment-behaves-correctly/Makefile b/tests/prod-environment-behaves-correctly/Makefile
--- a/tests/prod-environment-behaves-correctly/Makefile
+++ b/tests/prod-environment-behaves-correctly/Makefile
@@ -3,5 +3,12 @@
### We use PHPUnit to test several parts of our infrastructure.
###
+ENV_FOR_TEST_FULL= \
+ DOCKER_ACCESS=1 \
+ DOCKER_HOST=dwellers.nasqueron.org \
+
test:
phpunit .
+
+test-full:
+ sh -c "${ENV_FOR_TEST_FULL} phpunit ."
diff --git a/tests/prod-environment-behaves-correctly/utils/DockerContainer.php b/tests/prod-environment-behaves-correctly/utils/DockerContainer.php
new file mode 100644
--- /dev/null
+++ b/tests/prod-environment-behaves-correctly/utils/DockerContainer.php
@@ -0,0 +1,53 @@
+<?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`;
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Dec 19, 21:22 (18 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2306866
Default Alt Text
D62.diff (4 KB)

Event Timeline