Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mogtofu33 committed Apr 21, 2022
1 parent 1f12201 commit 1908bfc
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 46 deletions.
2 changes: 1 addition & 1 deletion 9.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ RUN chmod 777 /var/www \
# Convenient alias for root and www-data.
&& echo "alias ls='ls --color=auto -lAh'" >> /root/.bashrc \
&& echo "alias l='ls --color=auto -lAh'" >> /root/.bashrc \
&& echo "alias dr='drush --root=/opt/drupal'" >> /root/.bashrc \
&& echo "alias dr='drush --root=/opt/drupal/web'" >> /root/.bashrc \
&& cp /root/.bashrc /var/www/.bashrc \
&& chown www-data:www-data /var/www/.bashrc

Expand Down
27 changes: 27 additions & 0 deletions 9.3/tests/test_composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

def test_composer(host):
assert host.check_output('composer -V').startswith('Composer version 2')
assert host.file("/var/www/.composer/composer.json").exists

@pytest.mark.parametrize("bin", [
("parallel-lint"),
("pdepend"),
("phpcs"),
("phploc"),
("phpmd"),
("phpmetrics"),
("phpqa"),
("phpstan"),
("robo"),
])
def test_composer_bin(host, bin):
''' Test bin exist '''
assert host.file("var/www/.composer/vendor/bin/" + bin).exists
assert host.file("/usr/local/bin/" + bin).is_symlink
assert host.file("/usr/local/bin/" + bin).mode == 0o777

def test_phpcs_standard(host):
'''' Test phpcs standards '''
assert host.check_output('phpcs -i').__contains__('Drupal')
assert host.check_output('phpcs -i').__contains__('DrupalPractice')
8 changes: 8 additions & 0 deletions 9.3/tests/test_drush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

def test_drush(host):
''' Test drush exist '''
assert host.file("/opt/drupal/vendor/bin/drush").exists
assert host.file("/opt/drupal/vendor/bin/drush").mode == 0o755
assert host.file("drush --version").startwith("Drush Commandline Tool")
assert host.file("drush --root=/opt/drupal/web status --field=drupal-version").startwith("9.3")
20 changes: 20 additions & 0 deletions 9.3/tests/test_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

@pytest.mark.parametrize("name", [
("bash"),
("bc"),
("curl"),
("git"),
("jq"),
("gettext"),
("openssh"),
("xsltproc"),
("mariadb-client"),
("postgresql-client"),
("node"),
("yarn"),
])
def test_packages_installed(host, name):
''' Test a minimum of required packages '''
pkg = host.package(name)
assert pkg.is_installed
13 changes: 13 additions & 0 deletions 9.3/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

@pytest.mark.parametrize("folder", [
("/opt/drupal/web/core"),
("/opt/drupal/web/modules"),
("/opt/drupal/web/themes"),
("/opt/drupal/web/sites"),
("/var/www"),
])
def test_permissions(host, folder):
''' Test folder permissions '''
assert host.file(folder).user == "www-data"
assert host.file(folder).group == "www-data"
37 changes: 15 additions & 22 deletions 9.3/tests/test_php.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import pytest

def test_php_version(host):
''' Check PHP version so it's highlighted when changed '''
assert host.check_output('php -v').startswith('PHP 8.0')
''' Check PHP version so it's highlighted when changed '''
assert host.check_output('php -v').startswith('PHP 8.0')

# @pytest.mark.parametrize("name", [
# ("bcmath"),
# ("gd"),
# ("pdo_pgsql"),
# ("intl"),
# ("zip"),
# ("xsl"),
# ("OPcache"),
# ("apcu"),
# ("igbinary"),
# ("redis"),
# ])
# def test_php_modules(host, name):
# ''' Test the minimum list of needed extensions '''
# assert host.check_output('php -m | grep ' + name)

# def test_deploy_scripts_exists(host):
# assert host.file("/scripts/drupal-deploy.sh").exists
# assert host.file("/scripts/drupal-ensure-nfs.sh").exists
# assert host.file("/scripts/drupal-maintenance.sh").exists
@pytest.mark.parametrize("name", [
("sockets"),
("opcache"),
("ftp"),
("intl"),
("xsl"),
("mysqli"),
("Zend OPcache"),
("xdebug"),
])
def test_php_modules(host, name):
''' Test the minimum list of needed extensions '''
assert host.check_output('php -m | grep ' + name)
14 changes: 14 additions & 0 deletions 9.3/tests/test_php_ini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
import configparser

config = configparser.ConfigParser()

def test_php_ini(host):
assert host.file("/usr/local/etc/php/php.ini").exists

def test_php_ini_values(host):
''' Check important config that should be highlighted when changed '''
config.read('/usr/local/etc/php/php.ini')
assert config['PHP']['max_execution_time'] == '90'
assert config['PHP']['max_input_nesting_level'] == '512'
assert config['PHP']['memory_limit'] == '4G'
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ define prepare
@cp -r ./${TPL}/ ./$(1)/;
@IMAGE_TAG="$(1)" PHP_VERSION="$(2)" CORE_DEV="$(3)" envsubst < "./$(TPL)/Dockerfile" > "./$(1)/Dockerfile";
@IMAGE_TAG="$(1)" envsubst < "./$(TPL)/composer.json" > "./$(1)/composer.json";
@PHP_VERSION="$(2)" envsubst < "./$(TPL)/tests/test_php.py" > "./$(1)/tests/test_php.py";
@DRUPAL_VERSION="$(1)" envsubst < "./$(TPL)/tests/test_drush.py" > "./$(1)/tests/test_drush.py";
@echo "...Done!"
endef

Expand Down
2 changes: 1 addition & 1 deletion drupal-tpl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ RUN chmod 777 /var/www \
# Convenient alias for root and www-data.
&& echo "alias ls='ls --color=auto -lAh'" >> /root/.bashrc \
&& echo "alias l='ls --color=auto -lAh'" >> /root/.bashrc \
&& echo "alias dr='drush --root=/opt/drupal'" >> /root/.bashrc \
&& echo "alias dr='drush --root=/opt/drupal/web'" >> /root/.bashrc \
&& cp /root/.bashrc /var/www/.bashrc \
&& chown www-data:www-data /var/www/.bashrc

Expand Down
27 changes: 27 additions & 0 deletions drupal-tpl/tests/test_composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

def test_composer(host):
assert host.check_output('composer -V').startswith('Composer version 2')
assert host.file("/var/www/.composer/composer.json").exists

@pytest.mark.parametrize("bin", [
("parallel-lint"),
("pdepend"),
("phpcs"),
("phploc"),
("phpmd"),
("phpmetrics"),
("phpqa"),
("phpstan"),
("robo"),
])
def test_composer_bin(host, bin):
''' Test bin exist '''
assert host.file("var/www/.composer/vendor/bin/" + bin).exists
assert host.file("/usr/local/bin/" + bin).is_symlink
assert host.file("/usr/local/bin/" + bin).mode == 0o777

def test_phpcs_standard(host):
'''' Test phpcs standards '''
assert host.check_output('phpcs -i').__contains__('Drupal')
assert host.check_output('phpcs -i').__contains__('DrupalPractice')
8 changes: 8 additions & 0 deletions drupal-tpl/tests/test_drush.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest

def test_drush(host):
''' Test drush exist '''
assert host.file("/opt/drupal/vendor/bin/drush").exists
assert host.file("/opt/drupal/vendor/bin/drush").mode == 0o755
assert host.file("drush --version").startwith("Drush Commandline Tool")
assert host.file("drush --root=/opt/drupal/web status --field=drupal-version").startwith("$DRUPAL_VERSION")
20 changes: 20 additions & 0 deletions drupal-tpl/tests/test_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

@pytest.mark.parametrize("name", [
("bash"),
("bc"),
("curl"),
("git"),
("jq"),
("gettext"),
("openssh"),
("xsltproc"),
("mariadb-client"),
("postgresql-client"),
("node"),
("yarn"),
])
def test_packages_installed(host, name):
''' Test a minimum of required packages '''
pkg = host.package(name)
assert pkg.is_installed
13 changes: 13 additions & 0 deletions drupal-tpl/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

@pytest.mark.parametrize("folder", [
("/opt/drupal/web/core"),
("/opt/drupal/web/modules"),
("/opt/drupal/web/themes"),
("/opt/drupal/web/sites"),
("/var/www"),
])
def test_permissions(host, folder):
''' Test folder permissions '''
assert host.file(folder).user == "www-data"
assert host.file(folder).group == "www-data"
37 changes: 15 additions & 22 deletions drupal-tpl/tests/test_php.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import pytest

def test_php_version(host):
''' Check PHP version so it's highlighted when changed '''
assert host.check_output('php -v').startswith('PHP 8.0')
''' Check PHP version so it's highlighted when changed '''
assert host.check_output('php -v').startswith('PHP $PHP_VERSION')

# @pytest.mark.parametrize("name", [
# ("bcmath"),
# ("gd"),
# ("pdo_pgsql"),
# ("intl"),
# ("zip"),
# ("xsl"),
# ("OPcache"),
# ("apcu"),
# ("igbinary"),
# ("redis"),
# ])
# def test_php_modules(host, name):
# ''' Test the minimum list of needed extensions '''
# assert host.check_output('php -m | grep ' + name)

# def test_deploy_scripts_exists(host):
# assert host.file("/scripts/drupal-deploy.sh").exists
# assert host.file("/scripts/drupal-ensure-nfs.sh").exists
# assert host.file("/scripts/drupal-maintenance.sh").exists
@pytest.mark.parametrize("name", [
("sockets"),
("opcache"),
("ftp"),
("intl"),
("xsl"),
("mysqli"),
("Zend OPcache"),
("xdebug"),
])
def test_php_modules(host, name):
''' Test the minimum list of needed extensions '''
assert host.check_output('php -m | grep ' + name)
14 changes: 14 additions & 0 deletions drupal-tpl/tests/test_php_ini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
import configparser

config = configparser.ConfigParser()

def test_php_ini(host):
assert host.file("/usr/local/etc/php/php.ini").exists

def test_php_ini_values(host):
''' Check important config that should be highlighted when changed '''
config.read('/usr/local/etc/php/php.ini')
assert config['PHP']['max_execution_time'] == '90'
assert config['PHP']['max_input_nesting_level'] == '512'
assert config['PHP']['memory_limit'] == '4G'

0 comments on commit 1908bfc

Please sign in to comment.