aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-26 23:58:22 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-26 23:58:22 +0100
commit110ffae47db27a49bbc43f86ba3737bccc1b3085 (patch)
treed74934b12e2904b8aff5fe87421a6501b8ea5c8e /test
parentca27d6f6d9ccc35bf55db3d360d1d464d5e206e7 (diff)
downloadapp.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.gz
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.bz2
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.tar.xz
app.sh-110ffae47db27a49bbc43f86ba3737bccc1b3085.zip
o Rewriting most of this stuff to make it feel more like git.
Diffstat (limited to 'test')
-rwxr-xr-xtest/app-cat-conf.bats56
-rwxr-xr-xtest/app-common.bats14
-rwxr-xr-xtest/app-conf.bats165
-rwxr-xr-xtest/app-init.bats42
-rwxr-xr-xtest/app-install.bats9
-rw-r--r--test/data/app-cat-conf/config-17
-rw-r--r--test/data/app-cat-conf/config-21
-rw-r--r--test/data/app-cat-conf/config-34
-rwxr-xr-xtest/data/app-common/app-bar0
-rwxr-xr-xtest/data/app-common/app-faz0
-rwxr-xr-xtest/data/app-common/app-foo0
-rw-r--r--test/utils.bash78
12 files changed, 288 insertions, 88 deletions
diff --git a/test/app-cat-conf.bats b/test/app-cat-conf.bats
new file mode 100755
index 0000000..a95049a
--- /dev/null
+++ b/test/app-cat-conf.bats
@@ -0,0 +1,56 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+load utils
+
+setup_inner() {
+ export APPSH_DEFAULT_CONFIG=/dev/null
+}
+
+@test "app-cat-conf" {
+ app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1
+ echo_lines
+ eq '${lines[0]}' "baz.kiz=zap"
+ eq '${lines[1]}' "baz.wat=baz"
+ eq '${lines[2]}' "foo.bar=wat"
+ eq '${lines[3]}' "foo.baz=kaz"
+ eq '${lines[4]}' "foo.wat=foo"
+ eq '${#lines[*]}' 5
+}
+
+@test "app-cat-conf -g baz" {
+ app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1 -n "baz\..*"
+ echo_lines
+ eq '${lines[0]}' "baz.kiz=zap"
+ eq '${lines[1]}' "baz.wat=baz"
+ eq '${#lines[*]}' 2
+}
+
+@test "app-cat-conf -k wat" {
+ app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1 -n ".*\.wat"
+ echo_lines
+ eq '${lines[0]}' "baz.wat=baz"
+ eq '${lines[1]}' "foo.wat=foo"
+ eq '${#lines[*]}' 2
+}
+
+@test "app-cat-conf -g baz -k wat" {
+ app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1 -n "baz\.wat"
+ echo_lines
+ eq '${lines[0]}' "baz.wat=baz"
+ eq '${#lines[*]}' 1
+}
+
+@test "uses \$APPSH_DEFAULT_CONFIG" {
+ APPSH_DEFAULT_CONFIG=$APPSH_HOME/test/data/app-cat-conf/config-2
+ app_libexec app-cat-conf -f /dev/null
+ echo_lines
+ eq '${lines[0]}' "foo.bar=wat"
+ eq '${#lines[*]}' 1
+
+ app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-3
+ echo_lines
+ eq '${lines[0]}' "foo.bar=baz"
+ eq '${lines[1]}' "foo.wat=bar"
+ eq '${#lines[*]}' 2
+}
diff --git a/test/app-common.bats b/test/app-common.bats
new file mode 100755
index 0000000..d2173f5
--- /dev/null
+++ b/test/app-common.bats
@@ -0,0 +1,14 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+load utils
+
+@test "grep_path" {
+ . $APPSH_HOME/lib/common
+
+ x=`grep_path "app-.*" "$APPSH_HOME/test/data/app-common:/does-not-exist"|sort|sed s,$APPSH_HOME/,,|xargs`
+ [[ $x == "test/data/app-common/app-bar test/data/app-common/app-faz test/data/app-common/app-foo" ]]
+
+ x=`grep_path "app-f.*" "$APPSH_HOME/test/data/app-common:/does-not-exist"|sort|sed s,$APPSH_HOME/,,|xargs`
+ [[ $x == "test/data/app-common/app-faz test/data/app-common/app-foo" ]]
+}
diff --git a/test/app-conf.bats b/test/app-conf.bats
index 10e2757..08676d2 100755
--- a/test/app-conf.bats
+++ b/test/app-conf.bats
@@ -3,92 +3,117 @@
load utils
-@test "./app conf - happy day" {
- i=env-a
- n=app-a
-
- mkzip "app-a"
- app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n $n -i $i -v 1.0
- [ $status -eq 0 ]
-
- app -n $n -i $i conf; echo_lines
- [ $status -eq 0 ]
- [ "$output" = "app.bin bin/app-a " ]
+setup_inner() {
+ mkdir .app; touch .app/config
+ export APPSH_DEFAULT_CONFIG=/dev/null
+}
- app -n $n -i $i conf set group.foo bar; echo_lines
- [ $status -eq 0 ]
+@test "./app conf - happy day" {
+ app conf; echo_lines
+ echo "app.bin=bin/app-a" > .app/config
+ eq '$status' 0
+ eq '${#lines[*]}' 0
+
+ app conf set g.foo bar; echo_lines
+ eq '$status' 0
+
+ app conf; echo_lines
+ eq '$status' 0
+ eq '${lines[0]}' "app.bin bin/app-a "
+ eq '${lines[1]}' "g.foo bar "
+ eq '${#lines[*]}' 2
+
+ app conf get g.foo; echo_lines
+ eq '$status' 0
+ eq '${lines[0]}' "bar"
+ eq '${#lines[*]}' 1
+
+ app conf delete g.foo; echo_lines
+ eq '$status' 0
+
+ app conf; echo_lines
+ eq '$status' 0
+ eq '${lines[0]}' "app.bin bin/app-a "
+ eq '${#lines[*]}' 1
+}
- app -n $n -i $i conf; echo_lines
- [ $status -eq 0 ]
- [ "$output" = "app.bin bin/app-a
-group.foo bar " ]
+@test "./app conf - defaults to 'list'" {
+ echo "app.bin=bin/app-a" > .app/config
- app -n $n -i $i conf delete group.foo; echo_lines
- [ $status -eq 0 ]
+ app conf; echo_lines
+ eq '$status' 0
+ eq '${#lines[*]}' 1
+ eq '${lines[0]}' "app.bin bin/app-a "
+}
- app -n $n -i $i conf; echo_lines
- [ $status -eq 0 ]
- [ "$output" = "app.bin bin/app-a " ]
+@test "./app conf wat" {
+ app conf wat; echo_lines
+ eq '$status' 1
+ eq '${lines[0]}' "Error: Unknown command: wat"
}
@test "./app conf list" {
- i=env-a
- n=app-a
-
- mkzip "app-a"
- app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n $n -i $i -v 1.0
- [ $status -eq 0 ]
+ echo "app.bin=bin/app-a" > .app/config
- app -n $n -i $i conf; echo_lines
- [ $status -eq 0 ]
- [ "$output" = "app.bin bin/app-a " ]
+ app conf; echo_lines
+ eq '$status' 0
+ eq '${#lines[*]}' 1
+ eq '${lines[0]}' "app.bin bin/app-a "
- app -n $n -i $i conf list; echo_lines
- [ $status -eq 0 ]
- [ "$output" = "app.bin bin/app-a " ]
+ app conf list; echo_lines
+ eq '$status' 0
+ eq '${#lines[*]}' 1
+ eq '${lines[0]}' "app.bin bin/app-a "
- app -n $n -i $i conf list foo; echo_lines
- [ $status -eq 1 ]
+ app conf list foo; echo_lines
+ eq '$status' 1
}
-@test "./app conf list-group" {
- i=env-a
- n=app-a
-
- mkzip "app-a"
- app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n $n -i $i -v 1.0
- [ $status -eq 0 ]
-
- app -n $n -i $i conf set mygroup.a 1
- [ $status -eq 0 ]
- app -n $n -i $i conf set mygroup.b 1
- [ $status -eq 0 ]
- app -n $n -i $i conf set mygroup.c 2
- [ $status -eq 0 ]
- app -n $n -i $i conf set othergroup.a 1
- [ $status -eq 0 ]
-
- app -n $n -i $i conf list-group mygroup; echo_lines
- [ $status -eq 0 ]
- [ "$output" = "a 1
-b 1
-c 2 " ]
-}
+#@test "./app conf list-group" {
+# app conf set mygroup a 1
+# eq '$status' 0
+# app conf set mygroup b 1
+# eq '$status' 0
+# app conf set mygroup c 2
+# eq '$status' 0
+# app conf set othergroup a 1
+# eq '$status' 0
+#
+# app conf list; echo_lines
+# eq '$status' 0
+# app conf list-group mygroup; echo_lines
+# eq '$status' 0
+# eq '${lines[0]}' "mygroup.a 1 "
+# eq '${lines[1]}' "mygroup.b 1 "
+# eq '${lines[2]}' "mygroup.c 2 "
+# eq '${#lines[*]}' 3
+#}
@test "./app conf set" {
- i=env-a
- n=app-a
+ echo "app.bin=bin/app-a" > .app/config
- mkzip "app-a"
- app instance install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n $n -i $i -v 1.0
- [ $status -eq 0 ]
+ app conf set group; echo_lines
+ eq '$status' 1
- app -n $n -i $i conf set group; echo_lines
- [ $status -eq 1 ]
+ app conf set group.foo; echo_lines
+ eq '$status' 1
+
+ app conf set group.foo bar; echo_lines
+ eq '$status' 0
+ eq '${#lines[*]}' 0
+
+ app conf; echo_lines
+ eq '$status' 0
+ eq '${lines[0]}' "app.bin bin/app-a "
+ eq '${lines[1]}' "group.foo bar "
+ eq '${#lines[*]}' 2
+}
- app -n $n -i $i conf set group.foo; echo_lines
- [ $status -eq 1 ]
+@test "./app conf list - with duplicate entries" {
+ echo "foo.bar=awesome" > .app/config
+ echo "foo.bar=awesome" >> .app/config
- app -n $n -i $i conf set group.foo bar; echo_lines
- [ $status -eq 0 ]
+ app conf list; echo_lines
+ eq '$status' 0
+ eq '${lines[0]}' "foo.bar awesome "
}
diff --git a/test/app-init.bats b/test/app-init.bats
new file mode 100755
index 0000000..b62c42e
--- /dev/null
+++ b/test/app-init.bats
@@ -0,0 +1,42 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+load utils
+
+#@test "Invalid resolver" {
+# app init -d my-app wat; echo_lines
+# eq '$status' 1
+# eq '${#lines[*]}' 1
+# eq '${lines[0]}' "No such resolver: wat"
+#}
+
+#@test "Already installed" {
+# mkdir -p my-app/.apps
+# app init -d my-app maven; echo_lines
+# eq '$status' 1
+# eq '${#lines[*]}' 1
+# match '${lines[0]}' "my-app"
+#}
+
+@test "Happy day" {
+ mkzip app-a
+
+ REPO=$BATS_TMPDIR/repo
+
+ if [ ! -f $REPO/org/example/app-a/1.0-SNAPSHOT/maven-metadata.xml ]
+ then
+ mvn deploy:deploy-file -Durl=file://$REPO \
+ -Dfile=`echo $APPSH_HOME/test/data/app-a.zip` -DgeneratePom \
+ -DgroupId=org.example -DartifactId=app-a -Dversion=1.0-SNAPSHOT -Dpackaging=zip
+ fi
+
+ app init -d my-app maven -r "file://$BATS_TMPDIR/repo" org.example:app-a:1.0-SNAPSHOT; echo_lines
+ eq '$status' 0
+ eq '${lines[0]}' "Resolving version 1.0-SNAPSHOT..."
+ match '${lines[1]}' "Resolved version to 1.0-.*"
+ match '${lines[2]}' "Downloading org.example:app-a:1.0-.*"
+
+ eq '${#lines[*]}' 3
+
+ is_directory "my-app/.app"
+}
diff --git a/test/app-install.bats b/test/app-install.bats
index 38304be..18a84bc 100755
--- a/test/app-install.bats
+++ b/test/app-install.bats
@@ -5,12 +5,11 @@ load utils
# TODO: Add test for installing duplicate version
-@test "./app instance install app-a" {
+@test "./app install app-a" {
mkzip "app-a"
- app instance install \
+ app install \
-r file \
- -u $BATS_TEST_DIRNAME/data/app-a.zip \
- -n app-a -i prod
+ -u $BATS_TEST_DIRNAME/data/app-a.zip
echo_lines
[ $status -eq 0 ]
@@ -29,7 +28,7 @@ Postinstall completed successfully" ]
app instance install \
-r file \
-u $BATS_TEST_DIRNAME/data/install-test-env.zip \
- -n install-test-env -i prod -v 1.0
+ -v 1.0
echo_lines
[ $status -eq 0 ]
[ "$output" = "Creating instance 'prod' for 'install-test-env'
diff --git a/test/data/app-cat-conf/config-1 b/test/data/app-cat-conf/config-1
new file mode 100644
index 0000000..9d78d45
--- /dev/null
+++ b/test/data/app-cat-conf/config-1
@@ -0,0 +1,7 @@
+ foo.bar = wat
+foo.bar=wat
+foo.baz=kaz
+foo.wat=foo
+
+baz.wat=baz
+baz.kiz=zap
diff --git a/test/data/app-cat-conf/config-2 b/test/data/app-cat-conf/config-2
new file mode 100644
index 0000000..288815d
--- /dev/null
+++ b/test/data/app-cat-conf/config-2
@@ -0,0 +1 @@
+foo.bar=wat
diff --git a/test/data/app-cat-conf/config-3 b/test/data/app-cat-conf/config-3
new file mode 100644
index 0000000..569ea27
--- /dev/null
+++ b/test/data/app-cat-conf/config-3
@@ -0,0 +1,4 @@
+# same key as config-2, different value
+foo.bar=baz
+
+foo.wat=bar
diff --git a/test/data/app-common/app-bar b/test/data/app-common/app-bar
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/test/data/app-common/app-bar
diff --git a/test/data/app-common/app-faz b/test/data/app-common/app-faz
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/test/data/app-common/app-faz
diff --git a/test/data/app-common/app-foo b/test/data/app-common/app-foo
new file mode 100755
index 0000000..e69de29
--- /dev/null
+++ b/test/data/app-common/app-foo
diff --git a/test/utils.bash b/test/utils.bash
index cd21966..fa2602e 100644
--- a/test/utils.bash
+++ b/test/utils.bash
@@ -6,21 +6,25 @@ workdir=test-run
exit_usage=1
exit_usage_wrong=0
-echo_lines() {
- for line in "${lines[@]}"; do echo $line; done
- echo status=$status
-}
-
-APPSH=$(pwd)/app
-
setup() {
- APPSH_APPS=$BATS_TMPDIR/app.sh
- APPSH_HOME=$(cd $BATS_TEST_DIRNAME/../..; echo `pwd`/app.sh)
- APPSH_APPS_CANONICAL=$(cd -P $APPSH_APPS; pwd)
+ PATH=/bin:/usr/bin
+ PATH=$PATH:$APPSH_HOME
+ APPSH_HOME=$(cd $BATS_TEST_DIRNAME/..; echo `pwd`)
+
rm -rf $BATS_TMPDIR/app.sh
mkdir $BATS_TMPDIR/app.sh
cd $BATS_TMPDIR/app.sh
- ln -s $APPSH
+
+ 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() {
@@ -32,8 +36,16 @@ mkzip() {
}
app() {
- echo ./app $@
- run ./app $@
+ echo app $@
+ run $APPSH_HOME/app $@
+}
+
+app_libexec() {
+ local x=`PATH=$APPSH_HOME/libexec:/bin:/usr/bin which $1`
+
+ echo libexec/$@
+ shift
+ run "$x" $@
}
describe() {
@@ -59,3 +71,43 @@ can_not_read() {
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
+}
+
+match() {
+ local ex="$1"
+ local regex="$2"
+ local a="`eval echo $ex`"
+
+ if [[ $a =~ $regex ]]
+ then
+ return 0
+ fi
+
+ echo "Assertion failed: $ex =~ $a"
+ echo "Expected: $e"
+ echo "Actual: $a"
+ exit 1
+}