summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-10-17 15:20:45 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-10-17 15:20:45 +0200
commitd8890e75cf83504320ad12b657112cd5347fb600 (patch)
tree4a74422e225059597fdd61414991a723f41ef471
parent019129977ea279851386528be8a76ee33ff8392b (diff)
downloadapp.sh-d8890e75cf83504320ad12b657112cd5347fb600.tar.gz
app.sh-d8890e75cf83504320ad12b657112cd5347fb600.tar.bz2
app.sh-d8890e75cf83504320ad12b657112cd5347fb600.tar.xz
app.sh-d8890e75cf83504320ad12b657112cd5347fb600.zip
o Reworking conf to work as documented. Adding test case.
-rw-r--r--.app/lib/app-conf85
-rw-r--r--.app/lib/app-operate5
-rwxr-xr-xtest/app-conf.bats70
3 files changed, 129 insertions, 31 deletions
diff --git a/.app/lib/app-conf b/.app/lib/app-conf
index 6216d6f..39b2e0d 100644
--- a/.app/lib/app-conf
+++ b/.app/lib/app-conf
@@ -40,12 +40,12 @@ get_conf_all() {
local instance=$3
local file=$BASEDIR/$name/$instance/current/etc/app.conf
- if [ ! -r $file ]
+ if [ ! -r "$file" ]
then
return 0
fi
- sed -n "s,^[ ]*\($key_expr\)[ ]*=[ ]*\(.*\)$,\1=\2,p" $file | sort
+ sed -n "s,^[ ]*\($key_expr\)[ ]*=[ ]*\(.*\)$,\1=\2,p" "$file" | sort
}
get_conf_in_group() {
@@ -103,6 +103,17 @@ conf_delete() {
mv $file.tmp $file
}
+method_conf_list() {
+ local name=$1; shift
+ local instance=$1; shift
+
+ get_conf_all "$BASEDIR" "$name" "$instance" | (IFS==; while read key value
+ do
+ printf "%-20s %-20s" "$key" "$value"
+ echo
+ done)
+}
+
method_conf_usage() {
if [ -n "$1" ]
then
@@ -121,43 +132,57 @@ method_conf_usage() {
method_conf() {
local name="$1"; shift
local instance="$1"; shift
- local mode="list"
+ local method="$1"
- while getopts "s:d:" opt
- do
- case $opt in
- d)
- mode="delete"
- key="$OPTARG"
- ;;
- s)
- mode="set"
- key="$OPTARG"
- # Remove all options so far
- shift $((OPTIND-1))
- value="$1"
- ;;
- \?)
- method_conf_usage "Invalid option: -$OPTARG"
- ;;
- esac
- done
+ if [ $# -gt 0 ]
+ then
+ shift
+ fi
assert_is_instance conf_usage "$name" "$instance"
- case $mode in
+ case "$method" in
list)
- get_conf_all "$BASEDIR" "$name" "$instance" | (IFS==; while read key value
- do
- printf "%-20s %-20s" "$key" "$value"
- echo
- done)
+ if [ $# -gt 0 ]
+ then
+ method_conf_usage "Extra options."
+ exit 1
+ fi
+
+ method_conf_list "$name" "$instance"
;;
set)
- conf_set "$BASEDIR" "$name" "$instance" "$key" "$value"
+ if [ $# -ne 2 ]
+ then
+ method_conf_usage
+ exit 1
+ fi
+
+ conf_set "$BASEDIR" "$name" "$instance" "$1" "$2"
;;
delete)
- conf_delete "$BASEDIR" "$name" "$instance" "$key"
+ if [ $# -ne 1 ]
+ then
+ method_conf_usage
+ exit 1
+ fi
+
+ conf_delete "$BASEDIR" "$name" "$instance" "$1"
+ ;;
+ *)
+ if [ $# -eq 0 ]
+ then
+ method_conf_list "$name" "$instance"
+ exit 0
+ fi
+
+ if [ -z "$method" ]
+ then
+ method_conf_usage
+ else
+ method_conf_usage "Unknown method $method"
+ fi
+ exit 1
;;
esac
}
diff --git a/.app/lib/app-operate b/.app/lib/app-operate
index 8c9692b..e28df96 100644
--- a/.app/lib/app-operate
+++ b/.app/lib/app-operate
@@ -21,7 +21,9 @@ run_control() {
assert_is_instance operate_usage "$name" "$instance"
(
- cd $name/$instance/current
+ cd $name/$instance
+ APPSH_INSTANCE_HOME=`pwd`
+ cd current
bin=`get_conf $BASEDIR $name $instance app.method`
@@ -48,6 +50,7 @@ run_control() {
APPSH_HOME=$APPSH_HOME \
APPSH_NAME=$name \
APPSH_INSTANCE=$instance \
+ APPSH_INSTANCE_HOME=$APPSH_INSTANCE_HOME \
$bin
local ret=$?
set +x
diff --git a/test/app-conf.bats b/test/app-conf.bats
new file mode 100755
index 0000000..eb2d325
--- /dev/null
+++ b/test/app-conf.bats
@@ -0,0 +1,70 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+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 " ]
+
+ app -n $n -i $i conf set group.foo bar; echo_lines
+ [ $status -eq 0 ]
+
+ app -n $n -i $i conf; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app.bin bin/app-a
+group.foo bar " ]
+
+ app -n $n -i $i conf delete group.foo; echo_lines
+ [ $status -eq 0 ]
+
+ app -n $n -i $i conf; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app.bin bin/app-a " ]
+}
+
+@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 ]
+
+ app -n $n -i $i conf; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app.bin bin/app-a " ]
+
+ app -n $n -i $i conf list; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app.bin bin/app-a " ]
+
+ app -n $n -i $i conf list foo; echo_lines
+ [ $status -eq 1 ]
+}
+
+@test "./app conf set" {
+ 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 group; echo_lines
+ [ $status -eq 1 ]
+
+ app -n $n -i $i conf set group.foo; echo_lines
+ [ $status -eq 1 ]
+
+ app -n $n -i $i conf set group.foo bar; echo_lines
+ [ $status -eq 0 ]
+}