mirror of
https://github.com/dnote/dnote
synced 2026-03-14 14:35:50 +01:00
Write a smoke test for self-hosting (#310)
* Fix release script * Write a smoke testing for self-hosting * Allow to supply tarball path * Clear db
This commit is contained in:
parent
b699f1a643
commit
f519793273
9 changed files with 127 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
|||
/vendor
|
||||
/build
|
||||
/.vagrant
|
||||
.vagrant
|
||||
*.log
|
||||
|
|
|
|||
6
Makefile
6
Makefile
|
|
@ -73,6 +73,12 @@ else
|
|||
endif
|
||||
.PHONY: test-jslib
|
||||
|
||||
test-selfhost:
|
||||
@echo "==> running a smoke test for self-hosting"
|
||||
|
||||
@${currentDir}/host/smoketest/run_test.sh ${tarballPath}
|
||||
.PHONY: test-jslib
|
||||
|
||||
# development
|
||||
dev-server:
|
||||
@echo "==> running dev environment"
|
||||
|
|
|
|||
1
host/smoketest/.gitignore
vendored
Normal file
1
host/smoketest/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/volume
|
||||
1
host/smoketest/README.md
Normal file
1
host/smoketest/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
This directory contains a smoke test for running a self-hosted instance using a virtual machine.
|
||||
9
host/smoketest/Vagrantfile
vendored
Normal file
9
host/smoketest/Vagrantfile
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# -*- mode: ruby -*-
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "ubuntu/bionic64"
|
||||
config.vm.synced_folder './volume', '/vagrant'
|
||||
config.vm.network "forwarded_port", guest: 2300, host: 2300
|
||||
|
||||
config.vm.provision 'shell', path: './setup.sh', privileged: false
|
||||
end
|
||||
42
host/smoketest/run_test.sh
Executable file
42
host/smoketest/run_test.sh
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
# run_test.sh builds a fresh server image, and mounts it on a fresh
|
||||
# virtual machine and runs a smoke test. If a tarball path is not provided,
|
||||
# this script builds a new version and uses it.
|
||||
set -ex
|
||||
|
||||
# tarballPath is an absolute path to a release tarball containing the dnote server.
|
||||
tarballPath=$1
|
||||
|
||||
dir=$(dirname "${BASH_SOURCE[0]}")
|
||||
projectDir="$dir/../.."
|
||||
|
||||
# build
|
||||
if [ -z "$tarballPath" ]; then
|
||||
pushd "$projectDir"
|
||||
make version=integration_test build-server
|
||||
popd
|
||||
tarballPath="$projectDir/build/server/dnote_server_integration_test_linux_amd64.tar.gz"
|
||||
fi
|
||||
|
||||
pushd "$dir"
|
||||
|
||||
# start a virtual machine
|
||||
volume="$dir/volume"
|
||||
rm -rf "$volume"
|
||||
mkdir -p "$volume"
|
||||
cp "$tarballPath" "$volume"
|
||||
cp "$dir/testsuite.sh" "$volume"
|
||||
|
||||
vagrant up
|
||||
|
||||
# run tests
|
||||
set +e
|
||||
if ! vagrant ssh -c "/vagrant/testsuite.sh"; then
|
||||
echo "Test failed. Please see the output."
|
||||
vagrant halt
|
||||
exit 1
|
||||
fi
|
||||
set -e
|
||||
|
||||
vagrant halt
|
||||
popd
|
||||
17
host/smoketest/setup.sh
Executable file
17
host/smoketest/setup.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
sudo apt-get install wget ca-certificates
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
|
||||
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y postgresql-11
|
||||
|
||||
# set up database
|
||||
sudo -u postgres createdb dnote
|
||||
# allow connection from host and allow to connect without password
|
||||
sudo sed -i "/port*/a listen_addresses = '*'" /etc/postgresql/11/main/postgresql.conf
|
||||
sudo sed -i 's/host.*all.*.all.*md5/# &/' /etc/postgresql/11/main/pg_hba.conf
|
||||
sudo sed -i "$ a host all all all trust" /etc/postgresql/11/main/pg_hba.conf
|
||||
sudo service postgresql restart
|
||||
44
host/smoketest/testsuite.sh
Executable file
44
host/smoketest/testsuite.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
# testsuite.sh runs the smoke tests for a self-hosted instance.
|
||||
# It is meant to be run inside a virtual machine which has been
|
||||
# set up by an entry script.
|
||||
set -eu
|
||||
|
||||
echo 'Running a smoke test'
|
||||
|
||||
sudo -u postgres dropdb dnote
|
||||
sudo -u postgres createdb dnote
|
||||
|
||||
cd /vagrant
|
||||
|
||||
tar -xvf dnote_server_integration_test_linux_amd64.tar.gz
|
||||
|
||||
GO_ENV=PRODUCTION \
|
||||
DBHost=localhost \
|
||||
DBPort=5432 \
|
||||
DBName=dnote \
|
||||
DBUser=postgres \
|
||||
DBPassword="" \
|
||||
WebURL=localhost:3000 \
|
||||
./dnote-server -port 2300 start & sleep 3
|
||||
|
||||
assert_http_status() {
|
||||
url=$1
|
||||
expected=$2
|
||||
|
||||
echo "======== [TEST CASE] asserting response status code for $url ========"
|
||||
|
||||
got=$(curl --write-out %"{http_code}" --silent --output /dev/null "$url")
|
||||
|
||||
if [ "$got" != "$expected" ]; then
|
||||
echo "======== ASSERTION FAILED ========"
|
||||
echo "status code for $url: expected: $expected got: $got"
|
||||
echo "=================================="
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
assert_http_status http://localhost:2300 "200"
|
||||
assert_http_status http://localhost:2300/api/health "200"
|
||||
|
||||
echo "======== [SUCCESS] TEST PASSED! ========"
|
||||
|
|
@ -46,8 +46,13 @@ fi
|
|||
|
||||
echo "* creating release"
|
||||
set -x
|
||||
|
||||
# first line is the title and the rest are body in markdown
|
||||
message="$version_tag
|
||||
Please see the [CHANGELOG](https://github.com/dnote/dnote/blob/master/CHANGELOG.md)"
|
||||
|
||||
hub release create \
|
||||
"${file_flags[@]}" \
|
||||
"${flags[@]}" \
|
||||
--message="$version_tag\nPlease see the [CHANGELOG](https://github.com/dnote/dnote/blob/master/CHANGELOG.md)"\
|
||||
--message="$message"\
|
||||
"$version_tag"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue