-
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #7 from ochorocho/task/add-testing
Add tests bats core tests
- Loading branch information
Showing
8 changed files
with
222 additions
and
23 deletions.
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
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 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- '**' | ||
- '!main' | ||
jobs: | ||
build: | ||
name: Build and Test Container | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
version: [ v1.23, v1.22 ] | ||
steps: | ||
- | ||
name: Checkout code | ||
uses: actions/checkout@v3 | ||
- | ||
name: Docker info | ||
run: docker info | ||
- | ||
name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
platforms: linux/amd64,linux/arm64 | ||
- | ||
name: Setup BATS | ||
uses: mig4/setup-bats@v1 | ||
with: | ||
bats-version: 1.11.0 | ||
- | ||
name: Check out code | ||
uses: actions/checkout@v1 | ||
- | ||
name: "Test ddev ${{ matrix.version }} image" | ||
shell: 'script -q -e -c "bash {0}"' | ||
run: | | ||
sudo snap install yq | ||
./build.sh -v ${{ matrix.version }} -l | ||
DDEV_VERSION=${{ matrix.version }} bash bats tests |
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
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
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
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,36 @@ | ||
#!/usr/bin/env bats | ||
|
||
setup_suite() { | ||
NETWORK="ddev-docker" | ||
if docker network inspect "$NETWORK" &>/dev/null; then | ||
echo "Network '$NETWORK' already exists." | ||
else | ||
echo "Creating network '$NETWORK'." | ||
docker network create "$NETWORK" | ||
fi | ||
|
||
docker run --privileged -e DOCKER_TLS_CERTDIR="" --name ddev-dind -d --network ddev-docker --network-alias docker docker:dind | ||
waitForDinD | ||
} | ||
|
||
waitForDinD() { | ||
local TEST_COMMAND=" | ||
COUNT=0; | ||
while ! docker info > /dev/null 2>&1; do | ||
if [ \"\${COUNT}\" -ge 30 ]; then | ||
echo \"Could not connect to docker after \$COUNT seconds\" | ||
exit 1 | ||
fi | ||
sleep 1 | ||
COUNT=\$((COUNT + 1)); | ||
done | ||
" | ||
|
||
docker run --rm --network ddev-docker --name wait-for-docker-dind "docker:latest" /bin/sh -c "${TEST_COMMAND}" | ||
} | ||
|
||
teardown_suite() { | ||
docker stop ddev-dind | ||
docker rm ddev-dind | ||
} |
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,76 @@ | ||
#!/bin/bash | ||
|
||
@test "See docker version" { | ||
run docker-run "docker version -f json" | ||
|
||
version=$(echo "$output" | yq .Client.Version) | ||
regex='^([0-9]+)\.([0-9]+)\.([0-9]+)$' | ||
|
||
[[ $version =~ $regex ]] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "See ddev version" { | ||
run docker-run "ddev version -j" | ||
|
||
version=$(echo "$output" | tail -n 1 | yq '.raw.["DDEV version"]') | ||
regex='^v([0-9]+)\.([0-9]+)\.([0-9]+)$' | ||
|
||
[[ $version =~ $regex ]] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "See mkcert is installed" { | ||
run docker-run "mkcert -help" | ||
|
||
[[ "$output" == *"Usage of mkcert:"* ]] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "Create and run a ddev project" { | ||
local TEST_COMMAND=" | ||
mkdir ~/ddev-test | ||
cd ~/ddev-test | ||
echo '<?php echo \"Hello World\";' > index.php | ||
ddev config --project-type php --auto | ||
ddev config global --no-bind-mounts=true | ||
ddev start | ||
curl https://ddev-test.ddev.site/index.php | ||
ddev poweroff | ||
" | ||
run docker-run "${TEST_COMMAND}" | ||
|
||
[[ "$output" == *"Configuration complete. You may now run 'ddev start'"* ]] | ||
[[ "$output" == *"Hello World"* ]] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "Run ddev debug dockercheck" { | ||
run docker-run "ddev debug dockercheck" | ||
|
||
[[ "$output" == *"Able to run simple container that mounts a volume."* ]] | ||
[[ "$output" == *"Able to use internet inside container."* ]] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
# Use "--no-bind-mounts=true" to make "ddev debug test" pass. This is only required in testing environment | ||
@test "Run ddev debug test" { | ||
local TEST_COMMAND=" | ||
mkdir ~/ddev-test | ||
cd ~/ddev-test | ||
ddev config --project-type php --auto | ||
ddev config global --no-bind-mounts=true | ||
ddev debug test | ||
" | ||
run docker-run "${TEST_COMMAND}" | ||
|
||
[[ "$output" == *"All project containers are now ready."* ]] | ||
[[ "$output" == *"Successfully started tryddevproject-"* ]] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
docker-run() { | ||
local COMMAND=${1} | ||
|
||
docker run --rm -it --network ddev-docker ghcr.io/ochorocho/ddev-gitlab-ci:"${DDEV_VERSION}" /bin/sh -c "${COMMAND}" | ||
} |