Page MenuHomeDevCentral

No OneTemporary

diff --git a/composer.json b/composer.json
index 7186e37..69e3fb3 100644
--- a/composer.json
+++ b/composer.json
@@ -1,16 +1,22 @@
{
"name": "nasqueron/tests-prod-environment-behaves-correctly",
"description": "Tests to validate production environment",
"type": "project",
"require": {
- "phpunit/phpunit": "^7.3",
+ "phpunit/phpunit": "^9.5",
"ext-yaml": "*"
},
"license": "BSD-2-Clause",
"authors": [
{
"name": "Sébastien Santoro",
"email": "dereckson@espace-win.org"
}
- ]
+ ],
+ "autoload": {
+ "psr-4": {
+ "Nasqueron\\Infrastructure\\ProductionTests\\": "tests/",
+ "Nasqueron\\Infrastructure\\": "lib/Infrastructure"
+ }
+ }
}
diff --git a/utils/DockerContainer.php b/lib/Infrastructure/DockerContainer.php
similarity index 97%
rename from utils/DockerContainer.php
rename to lib/Infrastructure/DockerContainer.php
index 48b87fb..494d2e7 100644
--- a/utils/DockerContainer.php
+++ b/lib/Infrastructure/DockerContainer.php
@@ -1,50 +1,52 @@
<?php
+namespace Nasqueron\Infrastructure;
+
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
*/
public static function isValidHostname ($host) : bool {
return (bool)preg_match('/^[A-Za-z0-9\-\.]+$/', $host);
}
/**
* Determines if a container name is valid
*/
public static function isValidContainerName ($name) : bool {
//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) : string {
$output = `ssh $this->host sudo docker exec $this->container $command`;
return trim($output);
}
}
diff --git a/utils/OperationsConfiguration.php b/lib/Infrastructure/OperationsConfiguration.php
similarity index 100%
rename from utils/OperationsConfiguration.php
rename to lib/Infrastructure/OperationsConfiguration.php
diff --git a/phpunit.xml b/phpunit.xml
index 874e8f3..3e997f7 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,11 +1,12 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.3/phpunit.xsd"
+ bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Main">
- <directory>.</directory>
+ <directory>tests</directory>
<exclude>vendor</exclude>
</testsuite>
</testsuites>
</phpunit>
diff --git a/ApiServersLogTest.php b/tests/ApiServersLogTest.php
similarity index 72%
rename from ApiServersLogTest.php
rename to tests/ApiServersLogTest.php
index 58b6f23..b8a94b3 100644
--- a/ApiServersLogTest.php
+++ b/tests/ApiServersLogTest.php
@@ -1,18 +1,20 @@
<?php
-require_once 'traits/assertHttp.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class ApiServersLogTest extends PHPUnit\Framework\TestCase {
- use assertHttp;
+use PHPUnit\Framework\TestCase;
+
+class ApiServersLogTest extends TestCase {
+ use WithAssertHttp;
public function testAlive () {
$url = 'https://api.nasqueron.org/servers-log/status';
$this->assertHttpResponseCode(200, $url);
$this->assertSame('ALIVE', file_get_contents($url));
}
public function testPutEntryPointWithGetRequestReturns405 () {
$url = 'https://api.nasqueron.org/servers-log';
$this->assertHttpResponseCode(405, $url);
}
}
diff --git a/AuthGroveTest.php b/tests/AuthGroveTest.php
similarity index 79%
rename from AuthGroveTest.php
rename to tests/AuthGroveTest.php
index e9ab778..fb4bfb9 100644
--- a/AuthGroveTest.php
+++ b/tests/AuthGroveTest.php
@@ -1,30 +1,32 @@
<?php
-require_once 'traits/assertHttp.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class AuthGroveTest extends PHPUnit\Framework\TestCase {
- use assertHttp;
+use PHPUnit\Framework\TestCase;
+
+class AuthGroveTest extends TestCase {
+ use WithAssertHttp;
public function testTLS () {
$this->assertHttpResponseCode(301, 'http://login.nasqueron.org', 'Webserver should be configured to redirect http to https.');
$this->assertHttpResponseCode(200, 'https://login.nasqueron.org/auth/login', "Auth Grove HTTPS login page isn't reachable.");
}
public function testAlive () {
$url = 'https://login.nasqueron.org/status';
$this->assertHttpResponseCode(200, $url);
$this->assertSame('ALIVE', file_get_contents($url));
}
public function testHomepage () {
$url = 'https://login.nasqueron.org';
$this->assertHttpResponseCode(302, $url, '/ should redirect to login page');
$content = file_get_contents($url);
- $this->assertContains('https://login.nasqueron.org/auth/', $content);
+ $this->assertStringContainsString('https://login.nasqueron.org/auth/', $content);
}
public function testNotExisting () {
$this->assertHttpResponseCode(404, 'https://login.nasqueron.org/notexisting', 'A 404 code were expected for a not existing page.');
}
}
diff --git a/DevCentralDockerTest.php b/tests/DevCentralDockerTest.php
similarity index 70%
rename from DevCentralDockerTest.php
rename to tests/DevCentralDockerTest.php
index 185411b..63756f9 100644
--- a/DevCentralDockerTest.php
+++ b/tests/DevCentralDockerTest.php
@@ -1,54 +1,58 @@
<?php
-require_once 'utils/DockerContainer.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class DevCentralDockerTest extends PHPUnit\Framework\TestCase {
+use PHPUnit\Framework\TestCase;
+
+use Nasqueron\Infrastructure\DockerContainer;
+
+class DevCentralDockerTest extends TestCase {
private $container;
const DOCKER_CONTAINER = 'devcentral';
- protected function setUp () {
+ public function setUp () : void {
if (!getenv('DOCKER_ACCESS')) {
$this->markTestSkipped("No access to Docker engine.");
}
$this->container = new DockerContainer(getenv('DOCKER_HOST'), self::DOCKER_CONTAINER);
}
public function testInitialized () {
$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',
'phd-daemon',
];
foreach ($expectedProcesses as $expectedProcess) {
- $this->assertContains($expectedProcess, $processes, "The process $expectedProcess isn't currently launched.");
+ $this->assertStringContainsString($expectedProcess, $processes, "The process $expectedProcess isn't currently launched.");
}
}
public function testPhabricatorDaemons () {
$daemons = $this->container->exec("/opt/phabricator/bin/phd status");
$expectedDaemons = [
'PhabricatorRepositoryPullLocalDaemon',
'PhabricatorTaskmasterDaemon',
];
foreach ($expectedDaemons as $expectedDaemon) {
- $this->assertContains($expectedDaemon, $daemons, "The daemon $expectedDaemon isn't currently launched.");
+ $this->assertStringContainsString($expectedDaemon, $daemons, "The daemon $expectedDaemon isn't currently launched.");
}
}
}
diff --git a/DevCentralTest.php b/tests/DevCentralTest.php
similarity index 84%
rename from DevCentralTest.php
rename to tests/DevCentralTest.php
index 4b326f8..6cf3e96 100644
--- a/DevCentralTest.php
+++ b/tests/DevCentralTest.php
@@ -1,20 +1,22 @@
<?php
-require_once 'traits/assertHttp.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class DevCentralTest extends PHPUnit\Framework\TestCase {
- use assertHttp;
+use PHPUnit\Framework\TestCase;
+
+class DevCentralTest extends TestCase {
+ use WithAssertHttp;
public function testWebsiteIsUp () {
$this->assertHttpResponseCode(200, 'https://devcentral.nasqueron.org', "DevCentral HTTPS issue.");
$this->assertHttpResponseCode(500, 'https://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 testNginxRedirectsHttpToHttps () {
$this->assertHttpResponseCode(301, 'http://devcentral.nasqueron.org', 'Nginx should redirect http to https with a 301 code.');
}
public function testAphlictIsUp () {
$this->assertHttpResponseCode(405, 'http://equatower.nasqueron.org:22281/', 'Aphlict server seems down. Check if the aphlict container is launched on the Docker engine.');
}
}
diff --git a/EtherpadTest.php b/tests/EtherpadTest.php
similarity index 65%
rename from EtherpadTest.php
rename to tests/EtherpadTest.php
index c7f8a0f..00fd2ba 100644
--- a/EtherpadTest.php
+++ b/tests/EtherpadTest.php
@@ -1,26 +1,28 @@
<?php
-require_once 'traits/assertHttp.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class EtherpadTest extends PHPUnit\Framework\TestCase {
- use assertHttp;
+use PHPUnit\Framework\TestCase;
+
+class EtherpadTest extends TestCase {
+ use WithAssertHttp;
public function testEtherpadIsLive () {
$this->assertHttpResponseCode(301, 'http://pad.nasqueron.org/', "Etherpad isn't redirected on HTTP.");
$this->assertHttpResponseCode(200, 'https://pad.nasqueron.org/', "Etherpad looks down.");
$this->assertHttpResponseCode(200, 'https://pad.wolfplex.be', "Etherpad doesn't reply to pad.wolfplex.be vhost.");
$this->assertHttpResponseCode(404, 'https://pad.nasqueron.org/notexisting', 'A 404 code were expected for a not existing Etherpad page.');
$this->assertHttpResponseCode(200, 'https://pad.nasqueron.org/metrics', "ep_ether-o-meter plugin doesn't seem installed.");
}
public function testWolfplexApiWorks () {
//Reported by philectro - 09:42 < philectro> hey tous les pad ont disparu :o
$url = "https://api.wolfplex.org/pads/";
$this->assertHttpResponseCode(200, $url);
$stringOnlyAvailableWhenApiWorks = '","'; // pads titles separator
$currentContent = file_get_contents($url);
- $this->assertContains($stringOnlyAvailableWhenApiWorks, $currentContent, "On Ysul, /home/wolfplex.org/logs/api.log could help. But more probably, you reinstalled the Etherpad container without restoring the API key. Move the former APIKEY.txt file to /opt/etherpad-lite or, if lost, update Wolfplex API credentials with the new API key.");
+ $this->assertStringContainsString($stringOnlyAvailableWhenApiWorks, $currentContent, "On Ysul, /home/wolfplex.org/logs/api.log could help. But more probably, you reinstalled the Etherpad container without restoring the API key. Move the former APIKEY.txt file to /opt/etherpad-lite or, if lost, update Wolfplex API credentials with the new API key.");
}
}
diff --git a/NotificationsTest.php b/tests/NotificationsTest.php
similarity index 90%
rename from NotificationsTest.php
rename to tests/NotificationsTest.php
index 454cdac..abd7145 100644
--- a/NotificationsTest.php
+++ b/tests/NotificationsTest.php
@@ -1,45 +1,47 @@
<?php
-require_once 'traits/assertHttp.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class NotificationsTest extends PHPUnit\Framework\TestCase {
- use assertHttp;
+use PHPUnit\Framework\TestCase;
+
+class NotificationsTest extends TestCase {
+ use WithAssertHttp;
///
/// Alive tests
///
public function testIsLive () {
$this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org', 'Notifications center looks down.');
$this->assertHttpResponseCode(404, 'http://notifications.nasqueron.org/notexisting', 'A 404 code were expected for a not existing page.');
}
public function testSSL () {
$this->assertHttpResponseCode(200, 'https://notifications.nasqueron.org/', "Notifications center HTTPS issue.");
}
public function testAlive () {
$url = 'http://notifications.nasqueron.org/status';
$this->assertHttpResponseCode(200, $url);
$this->assertSame('ALIVE', file_get_contents($url));
}
///
/// Config tests
///
public function testGates () {
$this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org/gate/GitHub', 'Gate missing: check GitHub is declared');
$this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org/gate/Phabricator/Nasqueron', 'Gate missing: check DevCentral is declared in credentials.json');
}
public function testConfig () {
$url = 'https://notifications.nasqueron.org/config';
$this->assertHttpResponseCode(200, $url);
$this->assertJsonStringEqualsJsonFile(
__DIR__ . "/data/notifications.config.json",
file_get_contents($url),
"The Notifications Center configuration doesn't match the expected configuration hardcoded in this repository."
);
}
}
diff --git a/PaaSDockerTest.php b/tests/PaaSDockerTest.php
similarity index 80%
rename from PaaSDockerTest.php
rename to tests/PaaSDockerTest.php
index 50cd37d..7266bb1 100644
--- a/PaaSDockerTest.php
+++ b/tests/PaaSDockerTest.php
@@ -1,32 +1,33 @@
<?php
-require_once 'traits/assertHttp.php';
-require_once 'utils/OperationsConfiguration.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
+
+use PHPUnit\Framework\TestCase;
use Nasqueron\Infrastructure\OperationsConfiguration;
-class PaaSDockerTest extends PHPUnit\Framework\TestCase {
+class PaaSDockerTest extends TestCase {
- use assertHttp;
+ use WithAssertHttp;
/**
* @dataProvider provideDockerDomains
*
* @param string $domain A domain declared in the PaaS Docker configuration
* as an HTTP upstream block for a Docker container
*/
public function test502Pages (string $domain) : void {
$url = "https://$domain/502.html";
$this->assertHttpResponseCode(200, $url, "A 502 page is missing for $domain");
}
public function provideDockerDomains () : iterable {
$domains = OperationsConfiguration::getDockerDomains();
foreach ($domains as $domain) {
yield [$domain];
}
}
}
diff --git a/TommyTest.php b/tests/TommyTest.php
similarity index 88%
rename from TommyTest.php
rename to tests/TommyTest.php
index 58d68a5..a97abba 100644
--- a/TommyTest.php
+++ b/tests/TommyTest.php
@@ -1,42 +1,44 @@
<?php
-require_once 'traits/assertHttp.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class TommyTest extends PHPUnit\Framework\TestCase {
- use assertHttp;
+use PHPUnit\Framework\TestCase;
+
+class TommyTest extends TestCase {
+ use WithAssertHttp;
/**
* @dataProvider provideTommyInstances
*/
public function testIsLive (string $url) {
$this->assertHttpResponseCode(200, $url, 'Tommy looks down.');
$this->assertHttpResponseCode(404, $url . '/notexisting', 'A 404 code were expected for a not existing page.');
}
/**
* @dataProvider provideTommyInstances
*/
public function testAlive (string $url) {
$url = $url . '/status';
$this->assertHttpResponseCode(200, $url);
$this->assertSame('ALIVE', file_get_contents($url));
}
/**
* @dataProvider provideTommyInstances
*/
public function testDashboard (string $url, string $instance) {
$content = file_get_contents($url . '');
$this->assertContains($instance . '/job/', $content);
}
///
/// Data providers
///
public function provideTommyInstances () : iterable {
yield ["https://builds.nasqueron.org", "ci.nasqueron.org"];
yield ["https://infra.nasqueron.org/cd/dashboard", "cd.nasqueron.org"];
}
}
diff --git a/traits/assertHttp.php b/tests/WithAssertHttp.php
similarity index 86%
rename from traits/assertHttp.php
rename to tests/WithAssertHttp.php
index dec2143..39ceb31 100644
--- a/traits/assertHttp.php
+++ b/tests/WithAssertHttp.php
@@ -1,24 +1,28 @@
<?php
-trait assertHttp {
+namespace Nasqueron\Infrastructure\ProductionTests;
+
+use PHPUnit\Framework\TestCase;
+
+trait WithAssertHttp {
/**
* Asserts the HTTP response code of an URL matches the expected code
*/
private function assertHttpResponseCode (int $expectedCode, string $url, string $comment = '') : void {
$actualCode = $this->getHttpResponseCode($url);
$this->assertEquals($expectedCode, $actualCode, $comment);
}
/**
* Gets the HTTP response code of the specified URL
*/
private function getHttpResponseCode (string $url) : int {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, "Nasqueron-Ops-Tests");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $code;
}
}
diff --git a/ZedTest.php b/tests/ZedTest.php
similarity index 76%
rename from ZedTest.php
rename to tests/ZedTest.php
index 10c2f00..847fbe5 100644
--- a/ZedTest.php
+++ b/tests/ZedTest.php
@@ -1,22 +1,24 @@
<?php
-require_once 'traits/assertHttp.php';
+namespace Nasqueron\Infrastructure\ProductionTests;
-class ZedTest extends PHPUnit\Framework\TestCase {
- use assertHttp;
+use PHPUnit\Framework\TestCase;
+
+class ZedTest extends TestCase {
+ use WithAssertHttp;
public function testAlive () {
$url = 'https://hypership.space/';
$this->assertHttpResponseCode(200, $url);
}
public function testContentRootIsForbidden () {
$url = 'https://hypership.space/content/';
$this->assertHttpResponseCode(403, $url);
}
public function testContent () {
$url = 'https://hypership.space/content/scenes/B00002.png';
$this->assertHttpResponseCode(200, $url);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Oct 12, 07:39 (13 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3059781
Default Alt Text
(18 KB)

Event Timeline