diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-30 20:50:18 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-01-30 20:50:18 +0100 |
commit | 3b3c80db30af556d5da7301037bf16782216d0bd (patch) | |
tree | 8d4c5dac1a73e9a5bd0af4923982bc84566ffd24 | |
parent | a4215743db91c4b7050dfda32a670814a101b773 (diff) | |
download | app.sh-3b3c80db30af556d5da7301037bf16782216d0bd.tar.gz app.sh-3b3c80db30af556d5da7301037bf16782216d0bd.tar.bz2 app.sh-3b3c80db30af556d5da7301037bf16782216d0bd.tar.xz app.sh-3b3c80db30af556d5da7301037bf16782216d0bd.zip |
bin/app-init:
o Adding -p to mkdir so parent directories are created.
libexec/app-resolver-maven:
o Not using command expansion to make sure "set -e" works as normal.
o Adding a basic check that xmlstartlet has a useful output.
-rwxr-xr-x[-rw-r--r--] | STYLE-GUIDE.md | 5 | ||||
-rwxr-xr-x | bin/app-init | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | lib/common | 0 | ||||
-rwxr-xr-x | libexec/app-resolver-maven | 10 | ||||
-rwxr-xr-x | test/X-it-install-remove.bats | 45 | ||||
-rwxr-xr-x | test/app-conf.bats | 12 | ||||
-rwxr-xr-x | test/app-init.bats | 10 | ||||
-rwxr-xr-x | test/data/app-a/hooks/post-install | 13 | ||||
-rwxr-xr-x | test/it-install-remove.bats | 40 | ||||
-rwxr-xr-x[-rw-r--r--] | test/utils.bash | 12 |
10 files changed, 88 insertions, 61 deletions
diff --git a/STYLE-GUIDE.md b/STYLE-GUIDE.md index 1137425..dc897ba 100644..100755 --- a/STYLE-GUIDE.md +++ b/STYLE-GUIDE.md @@ -19,6 +19,11 @@ Creating `usage()` exit 1 } +Executing Commands +================== + +* http://unix.stackexchange.com/q/23026 + Resources --------- diff --git a/bin/app-init b/bin/app-init index d61f989..018b210 100755 --- a/bin/app-init +++ b/bin/app-init @@ -56,7 +56,7 @@ then exit 1 fi -mkdir -- "$dir" "$dir/.app" +mkdir -p -- "$dir" "$dir/.app" cd "$dir" app-conf set app.resolver "$resolver_name" diff --git a/lib/common b/lib/common index e90f77b..e90f77b 100644..100755 --- a/lib/common +++ b/lib/common diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven index a347abb..a3b367c 100755 --- a/libexec/app-resolver-maven +++ b/libexec/app-resolver-maven @@ -124,8 +124,14 @@ resolve_snapshot() { local r=$repo/$base_path/maven-metadata.xml get $r $l -# x=`xmlstarlet sel -t -m '//snapshotVersion[extension[text()="zip"]]' -v value $l` - set -- `xmlstarlet sel -t -m '/metadata/versioning/snapshot' -v "timestamp|buildNumber" $l` + x=$(xmlstarlet sel -t -m '/metadata/versioning/snapshot' -v "timestamp|buildNumber" $l) + set -- $x + + if [[ $# != 2 ]] + then + fatal "Unable extract a useful timestamp from maven-metadata.xml." + fi + snapshot_version="$1-$2" if [[ $snapshot_version == "" ]] diff --git a/test/X-it-install-remove.bats b/test/X-it-install-remove.bats deleted file mode 100755 index 78f4532..0000000 --- a/test/X-it-install-remove.bats +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bats -# vim: set filetype=sh: - -load utils - -@test "install remove roundtrip" { - mkzip "app-a" - name="app-a" - instance="prod" - a="-n $name -i $instance" - - describe "Installing $name/$instance" - app instance install \ - -r file \ - -u $BATS_TEST_DIRNAME/data/app-a.zip \ - -n $name -i $instance; echo_lines - [ $status -eq 0 ] - - can_not_read ".app/var/pid/$name-$instance.pid" - - describe "Setting property" - app -n $name -i $instance conf set env.TEST_PROPERTY awesome - [ $status -eq 0 ] - - describe "Starting $name/$instance" - app -n $name -i $instance operate start - echo_lines - [ $status -eq 0 ] - can_read .app/var/pid/$name-$instance.pid - - describe "Stopping $name/$instance" - app -n $name -i $instance operate stop - [ $status -eq 0 ] - echo_lines - can_not_read .app/var/pid/$name-$instance.pid - - can_read "$name/$instance/logs/$name.log" - can_read "$name/$instance/logs/$name.env" - can_read "$name/$instance/current/foo.conf" - - [ "`cat $name/$instance/logs/$name.env`" = "TEST_PROPERTY=awesome" ] - [ "`cat $name/$instance/current/foo.conf`" = "hello" ] - - # TODO: Remove the version -} diff --git a/test/app-conf.bats b/test/app-conf.bats index f85dbab..e805ff3 100755 --- a/test/app-conf.bats +++ b/test/app-conf.bats @@ -15,21 +15,25 @@ setup_inner() { eq '$status' 0 eq '${#lines[*]}' 0 - app conf set g.foo bar; echo_lines + 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[1]}' "g.FOO bar " eq '${#lines[*]}' 2 - app conf get g.foo; echo_lines + app conf get g.FOO; echo_lines eq '$status' 0 eq '${lines[0]}' "bar" eq '${#lines[*]}' 1 - app conf delete g.foo; echo_lines + app conf get g.foo; echo_lines + eq '$status' 0 + eq '${#lines[*]}' 0 + + app conf delete g.FOO; echo_lines eq '$status' 0 app conf; echo_lines diff --git a/test/app-init.bats b/test/app-init.bats index df3919e..2a3e1d8 100755 --- a/test/app-init.bats +++ b/test/app-init.bats @@ -20,15 +20,7 @@ load utils @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 + install_artifact app init -d my-app maven -r "file://$BATS_TMPDIR/repo" org.example:app-a:1.0-SNAPSHOT; echo_lines eq '$status' 0 diff --git a/test/data/app-a/hooks/post-install b/test/data/app-a/hooks/post-install index c548ad7..d4ca67a 100755 --- a/test/data/app-a/hooks/post-install +++ b/test/data/app-a/hooks/post-install @@ -4,6 +4,19 @@ set -u echo "Post install" +NAME=`basename $APP_HOME` + +echo NAME=$NAME +echo pwd=`pwd` +set -x +if [ -d root/etc/$NAME ] +then + find root/etc/$NAME -maxdepth 1 -type f | while read file + do + cp $file root/ + done +fi + [ -d ../../logs ] || mkdir ../../logs ln -s ../../../logs root/logs diff --git a/test/it-install-remove.bats b/test/it-install-remove.bats new file mode 100755 index 0000000..96bd2db --- /dev/null +++ b/test/it-install-remove.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "install remove roundtrip" { + mkzip "app-a" + install_artifact + + describe "Installing app" + app init -d my-app/prod maven -r $REPO_URL org.example:app-a:1.0-SNAPSHOT; echo_lines + eq '$status' 0 + + is_directory "my-app/prod/.app" + cd my-app/prod + + describe "Setting property" + app conf set env.TEST_PROPERTY awesome; echo_lines + eq '$status' 0 + + describe "Starting" + app start; echo_lines + eq '$status' 0 + can_read .app/pid + + describe "Stopping" + app stop + eq '$status' 0 + echo_lines + can_not_read .app/pid + + can_read "logs/app-a.log" + can_read "logs/app-a.env" + can_read "current/foo.conf" + + [ "`cat logs/app-a.env`" = "TEST_PROPERTY=awesome" ] + [ "`cat current/foo.conf`" = "hello" ] + + # TODO: Remove the version +} diff --git a/test/utils.bash b/test/utils.bash index 3a9d425..3c3f33f 100644..100755 --- a/test/utils.bash +++ b/test/utils.bash @@ -16,6 +16,9 @@ setup() { mkdir $BATS_TMPDIR/app.sh cd $BATS_TMPDIR/app.sh + REPO=$BATS_TMPDIR/repo + REPO_URL="file://$REPO" + if [ "`declare -f setup_inner >/dev/null; echo $?`" = 0 ] then setup_inner @@ -36,6 +39,15 @@ mkzip() { ) } +install_artifact() { + if [ ! -f $REPO/org/example/app-a/1.0-SNAPSHOT/maven-metadata.xml ] + then + mvn deploy:deploy-file -Durl=$REPO_URL \ + -Dfile=`echo $APPSH_HOME/test/data/app-a.zip` -DgeneratePom \ + -DgroupId=org.example -DartifactId=app-a -Dversion=1.0-SNAPSHOT -Dpackaging=zip + fi +} + app() { echo app $@ run $APPSH_HOME/app $@ |