aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.app/lib/app-app11
-rw-r--r--.app/lib/app-common9
-rwxr-xr-xtest/app-install.bats2
-rwxr-xr-xtest/app-list-versions.bats25
-rwxr-xr-xtest/app-list.bats102
-rw-r--r--test/utils.bash1
6 files changed, 143 insertions, 7 deletions
diff --git a/.app/lib/app-app b/.app/lib/app-app
index c9da2d7..cb87847 100644
--- a/.app/lib/app-app
+++ b/.app/lib/app-app
@@ -318,12 +318,12 @@ method_list_usage() {
method_list() {
local filter_name="$1"; shift
- local instance="$1"; shift
+ local filter_instance="$1"; shift
local mode="pretty"
local vars
local filter_name
- while getopts "P:n:" opt
+ while getopts "P:n:i:" opt
do
case $opt in
P)
@@ -333,6 +333,9 @@ method_list() {
n)
filter_name=$OPTARG
;;
+ i)
+ filter_instance=$OPTARG
+ ;;
\?)
method_list_usage "Invalid option: -$OPTARG"
;;
@@ -347,12 +350,12 @@ method_list() {
if [ $mode = "pretty" ]
then
printf "%-20s %-20s %-20s\n" "Name" "Instance" "Version"
- list_apps "$filter_name" name instance version | (IFS=:; while read name instance version
+ list_apps "$filter_name" "$filter_instance" name instance version | (IFS=:; while read name instance version
do
printf "%-20s %-20s %-20s\n" "$name" "$instance" "$version"
done)
else
- list_apps "$filter_name" $vars
+ list_apps "$filter_name" "$filter_instance" $vars
fi
}
diff --git a/.app/lib/app-common b/.app/lib/app-common
index 11e724b..584e053 100644
--- a/.app/lib/app-common
+++ b/.app/lib/app-common
@@ -33,8 +33,8 @@ assert_is_instance() {
}
list_apps() {
- filter_name=$1
- shift
+ filter_name=$1; shift
+ filter_instnace=$1; shift
vars="$@"
sort $BASEDIR/.app/var/list | while read line
@@ -46,6 +46,11 @@ list_apps() {
continue
fi
+ if [ -n "$filter_instance" -a "$filter_instance" != "$instance" ]
+ then
+ continue
+ fi
+
local line=""
IFS=" "; for var in $vars
do
diff --git a/test/app-install.bats b/test/app-install.bats
index 08c4a06..9961c84 100755
--- a/test/app-install.bats
+++ b/test/app-install.bats
@@ -3,6 +3,8 @@
load utils
+# TODO: Add test for installing duplicate version
+
@test "./app app install app-a" {
mkzip "app-a"
app app install \
diff --git a/test/app-list-versions.bats b/test/app-list-versions.bats
new file mode 100755
index 0000000..e9a70c2
--- /dev/null
+++ b/test/app-list-versions.bats
@@ -0,0 +1,25 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+load utils
+
+@test "./app app list-versions" {
+ mkzip "app-a"
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 &&
+ [ $status -eq 0 ]
+
+ app app list-versions -n app-a -i env-a; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Available versions for app-a/env-a:
+1.0
+1.1" ]
+
+ app app list-versions -n app-a -i env-a -P; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "1.0
+1.1" ]
+}
diff --git a/test/app-list.bats b/test/app-list.bats
new file mode 100755
index 0000000..4e56f00
--- /dev/null
+++ b/test/app-list.bats
@@ -0,0 +1,102 @@
+#!/usr/bin/env bats
+# vim: set filetype=sh:
+
+load utils
+
+@test "./app app list - all apps" {
+ mkzip "app-a"
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 &&
+ [ $status -eq 0 ]
+
+ app app list; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Name Instance Version
+app-a env-a 1.1
+app-a env-b 1.0
+app-b env-a 1.0
+app-b env-b 1.0 " ]
+
+ app app list -P name -P instance -P version; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app-a:env-a:1.1
+app-a:env-b:1.0
+app-b:env-a:1.0
+app-b:env-b:1.0" ]
+}
+
+@test "./app app list - -n filter" {
+ mkzip "app-a"
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 &&
+ [ $status -eq 0 ]
+
+ app app list -n foo; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Name Instance Version " ]
+
+ app app list -n app-a; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Name Instance Version
+app-a env-a 1.1
+app-a env-b 1.0 " ]
+
+ app app list -n app-a -P name -P instance -P version; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app-a:env-a:1.1
+app-a:env-b:1.0" ]
+}
+
+@test "./app app list - -i filter" {
+ mkzip "app-a"
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 &&
+ [ $status -eq 0 ]
+
+ app app list -i foo; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Name Instance Version " ]
+
+ app app list -i env-a; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Name Instance Version
+app-a env-a 1.1
+app-b env-a 1.0 " ]
+
+ app app list -i env-a -P name -P instance -P version; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app-a:env-a:1.1
+app-b:env-a:1.0" ]
+}
+
+@test "./app app list - -n + -i filter" {
+ mkzip "app-a"
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-a -v 1.1 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-a -i env-b -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-a -v 1.0 &&
+ app app install -r file -u $BATS_TEST_DIRNAME/data/app-a.zip -n app-b -i env-b -v 1.0 &&
+ [ $status -eq 0 ]
+
+ app app list -n foo -i bar; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Name Instance Version " ]
+
+ app app list -n app-a -i env-a; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "Name Instance Version
+app-a env-a 1.1 " ]
+
+ app app list -n app-a -i env-a -P name -P instance -P version; echo_lines
+ [ $status -eq 0 ]
+ [ "$output" = "app-a:env-a:1.1" ]
+}
diff --git a/test/utils.bash b/test/utils.bash
index 418b962..0edead8 100644
--- a/test/utils.bash
+++ b/test/utils.bash
@@ -19,7 +19,6 @@ setup() {
cd $BATS_TMPDIR/app.sh
ln -s $APPSH
WORK=$(cd -P $BATS_TMPDIR/app.sh; pwd)
- echo WORK=$WORK
}
mkzip() {