summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/my-webapp/root/app.js37
-rw-r--r--test/it.bats28
-rw-r--r--test/utils.bash176
3 files changed, 241 insertions, 0 deletions
diff --git a/test/data/my-webapp/root/app.js b/test/data/my-webapp/root/app.js
new file mode 100644
index 0000000..29298b3
--- /dev/null
+++ b/test/data/my-webapp/root/app.js
@@ -0,0 +1,37 @@
+var http = require("http"),
+ url = require("url"),
+ path = require("path"),
+ fs = require("fs")
+ port = process.env.PORT || 8888;
+
+http.createServer(function(request, response) {
+
+ var uri = url.parse(request.url).pathname
+ , filename = path.join(process.cwd(), uri);
+
+ path.exists(filename, function(exists) {
+ if(!exists) {
+ response.writeHead(404, {"Content-Type": "text/plain"});
+ response.write("404 Not Found\n");
+ response.end();
+ return;
+ }
+
+ if (fs.statSync(filename).isDirectory()) filename += '/index.html';
+
+ fs.readFile(filename, "binary", function(err, file) {
+ if(err) {
+ response.writeHead(500, {"Content-Type": "text/plain"});
+ response.write(err + "\n");
+ response.end();
+ return;
+ }
+
+ response.writeHead(200);
+ response.write(file, "binary");
+ response.end();
+ });
+ });
+}).listen(parseInt(port, 10));
+
+console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");
diff --git a/test/it.bats b/test/it.bats
new file mode 100644
index 0000000..d594049
--- /dev/null
+++ b/test/it.bats
@@ -0,0 +1,28 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+load utils
+
+@test "Happy day" {
+ mkzip my-webapp
+ install_artifact "my-webapp"
+ install_artifact "my-webapp" 1.0
+
+ cd $BATS_TMPDIR
+ cd appstore
+ mkdir -p client server
+ cd client
+
+ appstore init "localhost" "$BATS_TMPDIR/appstore/server" "mysetup"
+ cd mysetup
+
+ # Making assertions easier.
+ git config user.name "Test Case"
+ git config user.email tester@example.org
+
+ echo "app-1,maven,org.example:app-a:1.0-SNAPSHOT,1.0-SNAPSHOT,enabled" >> apps.csv
+ git commit -m "o Adding app-1." -a
+ git push cloud master
+ eq "ssh://localhost$BATS_TMPDIR/appstore/server/mysetup" `git config remote.cloud.url`
+ eq 1 2
+}
diff --git a/test/utils.bash b/test/utils.bash
new file mode 100644
index 0000000..cd6fcf0
--- /dev/null
+++ b/test/utils.bash
@@ -0,0 +1,176 @@
+#!/bin/bash
+
+workdir=test-run
+
+# TODO: assert that the exit code is 1 for 'usage' outputs.
+exit_usage=1
+exit_usage_wrong=0
+
+setup() {
+ ORIG_PATH=$PATH
+ APPSTORE_HOME=$(cd $BATS_TEST_DIRNAME/..; echo `pwd`)
+ PATH=/bin:/usr/bin
+ PATH=$PATH:$APPSTORE_HOME
+
+ rm -rf $BATS_TMPDIR/appstore
+ mkdir $BATS_TMPDIR/appstore
+
+ HOME=$BATS_TMPDIR/appstore-home
+
+ cd $BATS_TMPDIR/appstore
+
+ REPO=$BATS_TMPDIR/repo
+ REPO_URL="file://$REPO"
+ FIXED_REPO_URL="file://`fix_path $REPO`"
+
+ if [ "`declare -f setup_inner >/dev/null; echo $?`" = 0 ]
+ then
+ setup_inner
+ fi
+}
+
+echo_lines() {
+ echo lines:
+ for line in "${lines[@]}"; do echo $line; done
+ echo status=$status
+}
+
+mkzip() {
+(
+ cd $BATS_TEST_DIRNAME/data/$1
+ rm -f ../$1.zip
+ zip -qr ../$1.zip *
+)
+}
+
+install_artifact() {
+ local artifactId=${1}; shift
+ local version=${1-1.0-SNAPSHOT}
+ describe -Dfile=`fix_path $APPSTORE_HOME/test/data/$artifactId.zip` -DgeneratePom
+ PATH=$ORIG_PATH mvn deploy:deploy-file -Durl=$FIXED_REPO_URL \
+ -Dfile=`fix_path $APPSTORE_HOME/test/data/$artifactId.zip` -DgeneratePom \
+ -DgroupId=org.example -DartifactId=$artifactId -Dversion=$version -Dpackaging=zip
+}
+
+check_status=yes
+
+app() {
+ echo app $@
+ run $APPSTORE_HOME/app $@
+ echo_lines
+
+ if [ "$check_status" = yes ]
+ then
+ eq '$status' 0
+ fi
+
+ check_status=yes
+}
+
+app_libexec() {
+ local x=`PATH=$APPSTORE_HOME/libexec:/bin:/usr/bin which $1`
+
+ echo libexec/$@
+ shift
+ run "$x" $@
+
+ echo_lines
+
+ if [ "$check_status" = yes ]
+ then
+ eq '$status' 0
+ fi
+
+ check_status=yes
+}
+
+fix_path_uname=`uname -s`
+fix_path() {
+ case $fix_path_uname in
+ CYGWIN_NT*)
+ cygpath -wa $1
+ ;;
+ *)
+ echo $1
+ ;;
+ esac
+}
+
+describe() {
+ echo "# " $@ >&3
+}
+
+can_read() {
+ if [ -r "$1" ]
+ then
+ return 0
+ else
+ echo "Can't read $1"
+ return 1
+ fi
+}
+
+can_not_read() {
+ if [ ! -r "$1" ]
+ then
+ return 0
+ else
+ echo "Can read $1"
+ return 1
+ fi
+}
+
+is_directory() {
+ if [ ! -d "$1" ]
+ then
+ echo "Not a directory: $1" 2>&1
+ return 1
+ fi
+}
+
+eq() {
+ local ex="$1"
+ local e="$2"
+ local a="`eval echo $ex`"
+
+ if [[ $e == $a ]]
+ then
+ return 0
+ fi
+
+ echo "Assertion failed: $ex"
+ echo "Expected: $e"
+ echo "Actual: $a"
+ exit 1
+}
+
+neq() {
+ local ex="$1"
+ local e="$2"
+ local a="`eval echo $ex`"
+
+ if [[ $e != $a ]]
+ then
+ return 0
+ fi
+
+ echo "Not-equal assertion failed: $ex"
+ echo "Expected: $e"
+ echo "Actual: $a"
+ exit 1
+}
+
+match() {
+ local ex="$1"
+ local regex="$2"
+ local a="`eval echo $ex`"
+
+ if [[ $a =~ $regex ]]
+ then
+ return 0
+ fi
+
+ echo "Match failed: $ex =~ $regex"
+ echo "Value: $a"
+ exit 1
+}