-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from Metadrop/feature/add-testing-base
Feature/add testing base
- Loading branch information
Showing
14 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
Folder with conifguration and data used by GitHub during the development of the Drupal Boilerplate itself. It can be safely removed if you are just using Drupal Boilerplate for a Drupal project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Shellspec]](https://github.com/shellspec/shellspec) is teting framework for shell scripts used to test the Drupal Boilerplate. It allows to run comanmds, examine the output, check the status results and more. | ||
|
||
The `shellspec` file is the Shellspec configuration file used for the tests. | ||
|
||
Inside the `shellspec_spec` folder all the spec or tests can be found. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
--default-path "shellspec_spec" | ||
|
||
--helperdir shellspec_spec | ||
|
||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Describe 'BackstopJS' backstopjs | ||
|
||
It 'is installed and can be run' | ||
When run command docker-compose exec -T backstopjs backstop | ||
The status should be success | ||
The output should include "Welcome to BackstopJS" | ||
End | ||
|
||
It 'can create reference images' | ||
When run command make backstopjs-reference | ||
The status should be success | ||
The output should include "BackstopJS" | ||
The output should include "CREATING NEW REFERENCE FILE" | ||
The output should include 'Command "reference" successfully executed' | ||
End | ||
|
||
It 'can compare site with reference images' | ||
When run command make backstopjs-test | ||
The status should be success | ||
The output should include "BackstopJS" | ||
The output should include 'Command "test" successfully executed' | ||
End | ||
End | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Describe 'Behat' behat | ||
|
||
It 'is installed and can be run' | ||
When run command make behat | ||
The status should be success | ||
The output should include "Goutte driver works" | ||
The output should include "Selenium driver works" | ||
End | ||
|
||
|
||
End | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
%const CONTAINER_NAMES: "php traefik node hub chrome backstopjs mkdocs mariadb apache adminer mailhog" | ||
%const CONTAINER_COUNT: 11 | ||
|
||
Describe 'Container infrastructure:' containers | ||
|
||
Context 'container' | ||
Parameters:value $CONTAINER_NAMES | ||
|
||
It "'$1' container is running" | ||
When call container_is_alive $1 | ||
The status should be success | ||
End | ||
End | ||
|
||
Context 'running container count' | ||
|
||
It "must be $CONTAINER_COUNT" | ||
When call container_count | ||
The output should equal $CONTAINER_COUNT | ||
End | ||
End | ||
End | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Describe 'Drush' drush | ||
|
||
It 'is installed and can be run' | ||
When run command make drush | ||
The status should be success | ||
The output should include "Drush Commandline Tool" | ||
End | ||
|
||
It 'has access to the Drupal database' | ||
When run command make drush status | ||
The status should be success | ||
The output should include "Database : Connected" | ||
End | ||
|
||
# Make sure drush can access a full boostrapped Drupal. | ||
It 'can generate one-time login links' | ||
When run command make drush uli | ||
The status should be success | ||
The output should include "http://" | ||
The output should include "/user/reset/1/" | ||
End | ||
End | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Describe 'Boilerplate folder structure' folders | ||
|
||
It 'has main boilerplate folders' | ||
|
||
The path 'backups' should be directory | ||
The path 'config' should be directory | ||
The path 'docs' should be directory | ||
The path 'drush' should be directory | ||
The path 'patches' should be directory | ||
The path 'private-files' should be directory | ||
The path 'reports' should be directory | ||
The path 'scripts' should be directory | ||
The path 'solr/cores' should be directory | ||
The path 'tests/common' should be directory | ||
The path 'tests/environment' should be directory | ||
The path 'tests/functional' should be directory | ||
The path 'tmp' should be directory | ||
The path 'vendor' should be directory | ||
The path 'web' should be directory | ||
End | ||
|
||
It 'has main boilerplate files' | ||
The path 'composer.json' should be file | ||
The path 'behat.yml' should be file | ||
The path 'docker-compose.yml' should be file | ||
The path "docker-compose.override.yml" should be file | ||
The path "web/sites/default/settings.local.php" should be file | ||
End | ||
|
||
It 'has main boilerplate symlinks' | ||
|
||
The path 'public_html' should be symlink | ||
The path 'docroot' should be symlink | ||
End | ||
|
||
|
||
|
||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Describe 'Grumphp' grumphp static-code-analisys git | ||
|
||
It 'has its configuration file in place' | ||
The path 'grumphp.yml' should be file | ||
End | ||
End | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Describe 'Phpqa' phpqa static-code-analisys | ||
|
||
It 'has its configuration file in place' | ||
The path '.phpqa.yml' should be file | ||
End | ||
|
||
# Test disabled because Radix includes a file with a phpqa error in the file | ||
# src/kits/radix_starterkit/includes/theme.inc | ||
# It 'should detect no errors' | ||
# When run command docker-compose exec php phpqa | ||
# The status should be success | ||
# The output should include 'No failed tools' | ||
# The error should not include 'This is a dummy text to discard standard error output' | ||
# End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%const SCRIPTHOR_SCRIPTS: "backup.sh copy-content-config-entity-to-module.sh frontend-build.sh reload-local.sh setup-traefik-port.sh" | ||
|
||
Describe 'Scripthor' scripthor | ||
|
||
Context 'script' | ||
Parameters:value $SCRIPTHOR_SCRIPTS | ||
|
||
It "'$1' is symlinked" | ||
The path "scripts/$1" should be symlink | ||
The path "scripts/$1" should be readable | ||
End | ||
End | ||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# shellcheck shell=sh | ||
|
||
# Defining variables and functions here will affect all specfiles. | ||
# Change shell options inside a function may cause different behavior, | ||
# so it is better to set them here. | ||
# set -eu | ||
|
||
# This callback function will be invoked only once before loading specfiles. | ||
spec_helper_precheck() { | ||
# Available functions: info, warn, error, abort, setenv, unsetenv | ||
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION | ||
: minimum_version "0.28.1" | ||
} | ||
|
||
# This callback function will be invoked after a specfile has been loaded. | ||
spec_helper_loaded() { | ||
: | ||
} | ||
|
||
# This callback function will be invoked after core modules has been loaded. | ||
spec_helper_configure() { | ||
# Available functions: import, before_each, after_each, before_all, after_all | ||
: import 'support/custom_matcher' | ||
} | ||
|
||
|
||
# Custom functions | ||
################## | ||
|
||
# Checks if a given container is running. | ||
# $1: name of the container. | ||
container_is_alive() { | ||
count=$(docker-compose ps --services --filter "status=running" | grep $1| wc -l) | ||
if [ $count -eq "1" ] | ||
then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
container_count() { | ||
docker-compose ps --services --filter "status=running" | wc -l | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Bash tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Add HTTP basic auth credentials | ||
run: | | ||
echo "auth.json path: $GITHUB_WORKSPACE/auth.json" | ||
echo '${{ secrets.auth_json_for_boierpalte_github_ci }}' > $GITHUB_WORKSPACE/auth.json | ||
pwd | ||
- name: Prepare container for testing | ||
id: testing-container-setup | ||
run: | | ||
ROOT_PATH=/boilerplate_tests | ||
docker_hub_image=metadrop/drupal-boilerplate-dind:v0.3 | ||
echo "----- Get image to run the tests -----" | ||
docker pull $docker_hub_image | ||
echo "----- Create a docker container from the downloaded image -----" | ||
CONTAINER_ID=$(docker run -d --privileged --name testrunner --mount type=bind,source=.,target=$ROOT_PATH $docker_hub_image) | ||
echo "----- Container ID is $CONTAINER_ID -----" | ||
sleep 5 | ||
docker ps | ||
echo "----- Make docker available for the tester user (dirty trick? How to improve it?) -----" | ||
docker exec $CONTAINER_ID chown :tester /var/run/docker.sock | ||
echo "----- Export container id to other steps -----" | ||
echo "CONTAINER_ID=$CONTAINER_ID" >> "$GITHUB_OUTPUT" | ||
echo "ROOT_PATH=$ROOT_PATH" >> "$GITHUB_OUTPUT" | ||
- name: Prepare shellspec | ||
env: | ||
CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} | ||
ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} | ||
run: | | ||
echo "----- Download and uncompress shellspec, the test framework used for testing -----" | ||
docker exec $CONTAINER_ID wget https://github.com/shellspec/shellspec/releases/download/0.28.1/shellspec-dist.tar.gz -O /opt/shellspec-dist.tar.gz | ||
docker exec $CONTAINER_ID tar xfvz /opt/shellspec-dist.tar.gz -C /opt/ | ||
echo "----- Copy shellspec config file to the root folder -----" | ||
ln -s .github/shellspec/shellspec .shellspec | ||
echo "----- Copy shellspec test files -----" | ||
ln -s .github/shellspec/shellspec_spec shellspec_spec | ||
- name: Setup Git cli | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "CI tester" | ||
- name: Set ownership | ||
run: sudo chown 1000 -R . | ||
|
||
- name: Run composer install | ||
env: | ||
CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} | ||
ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} | ||
run: | | ||
docker exec -u tester -w $ROOT_PATH/ $CONTAINER_ID composer install --ignore-platform-reqs | ||
- name: Run boilerplate assistant | ||
env: | ||
CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} | ||
ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} | ||
run: | | ||
docker exec -u tester -w $ROOT_PATH/ $CONTAINER_ID composer boilerplate:assistant | ||
- name: Run tests | ||
env: | ||
CONTAINER_ID: ${{ steps.testing-container-setup.outputs.CONTAINER_ID }} | ||
ROOT_PATH: ${{ steps.testing-container-setup.outputs.ROOT_PATH }} | ||
run: | | ||
docker exec -u tester -w $ROOT_PATH/ $CONTAINER_ID /opt/shellspec/shellspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters