Skip to content

Commit

Permalink
Dockerized validation test (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzen authored Feb 13, 2020
1 parent 24ee184 commit 6b6ff0a
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 25 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ LABEL maintainer="[email protected]"

COPY conf/nginx.conf /etc/nginx/conf.d/default.conf

# /usr/share/nginx/html is also hardcoded in test/run-test.sh
COPY --from=0 /root/src/public/ /usr/share/nginx/html
42 changes: 18 additions & 24 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#!/usr/bin/env bash

# validate generated html content
bin/build.sh

# build image that contains the content
docker build -t decred/dcrweb-test test

echo -n "Starting nu validator "

docker run -d --rm --name nu_validator -p 8888:8888 validator/validator:latest || exit 1
# run nu-validator service
docker stop validator 2>/dev/null

docker run \
-d --rm \
--name validator \
-p 8888:8888 validator/validator:latest || exit 1

# wait for the service to start up
# wait for the validator service to start up

while true; do
curl -qqq localhost:8888 2>/dev/null >/dev/null && break
Expand All @@ -15,29 +25,13 @@ while true; do
done

echo
echo -n "Validating pages "

FILES=$(find src/public -name \*.html | grep -v google)
PATH=node_modules/.bin:$PATH

exit_code=0
error_files=""

for file in $FILES; do
echo -n .
html-validator --quiet --errors-only --validator='http://localhost:8888' --file=$file && continue
error_files="$error_files $file"
exit_code=1
done
docker run --rm --link validator decred/dcrweb-test

echo done
exit_code=$?

if [ $exit_code != "0" ]; then
echo "errors found: $error_files"
else
echo "no errors found"
fi

docker stop nu_validator >/dev/null
echo -n "Stopping validator..."
docker stop validator 2>/dev/null
echo

exit $exit_code
exit $exit_code
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"url": "https://github.com/decred/dcrweb/issues"
},
"homepage": "https://github.com/decred/dcrweb#readme",
"dependencies": {
"devDependencies": {
"html-validator-cli": "^6.0.2",
"netlify-cli": "^2.6.6"
}
Expand Down
19 changes: 19 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM decred/dcrweb:latest

WORKDIR /root

RUN apt-get update && apt-get install -y curl

COPY package.json run-test.sh ./

ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION v8

RUN mkdir -p $NVM_DIR && \
curl -s -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

# install node and npm
RUN . $NVM_DIR/nvm.sh \
&& npm install

CMD ["bash", "-lc", "./run-test.sh"]
12 changes: 12 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "dcrweb-test",
"version": "1.0.0",
"description": "dcrweb testbed",
"main": "index.js",
"bin": {},
"author": "Peter Banik <[email protected]>",
"license": "ISC",
"devDependencies": {
"html-validator-cli": "^6.0.2"
}
}
41 changes: 41 additions & 0 deletions test/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# validate generated html content

CONTENT_DIR=/usr/share/nginx/html

if [ "$1" != "" ]; then
CONTENT_DIR=$1
fi

echo
echo "Validating pages "

FILES=$(find $CONTENT_DIR -name \*.html | grep -v google)
PATH=node_modules/.bin:$PATH

exit_code=0
error_files=""

for file in $FILES; do
echo -n .
html-validator \
--quiet \
--errors-only \
--validator='http://validator:8888' \
--file=$file && continue
error_files="$error_files $file"
exit_code=1
done

echo
echo "Validation completed"

if [ $exit_code != "0" ]; then
echo "Errors found:"
echo $error_files | sed "s|$CONTENT_DIR/|\t|g" | sed 's/ /\n/g'
else
echo "No errors found."
fi

exit $exit_code

0 comments on commit 6b6ff0a

Please sign in to comment.