aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/01-add.test31
-rw-r--r--test/02-list.test39
-rw-r--r--test/03-flush.test14
-rw-r--r--test/04-rebuild.test21
-rw-r--r--test/05-remove.test29
-rw-r--r--test/06-default.test25
-rw-r--r--test/lib.sh84
-rw-r--r--test/setup.sh16
8 files changed, 259 insertions, 0 deletions
diff --git a/test/01-add.test b/test/01-add.test
new file mode 100644
index 0000000..b4d223f
--- /dev/null
+++ b/test/01-add.test
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+header "bosun add"
+
+assert success "add host-baz" "$BOSUN_CMD" add host-baz
+
+want <<EOF
+./make.conf -> stow/host-baz/make.conf
+./package.accept_keywords -> stow/service-bar/package.accept_keywords
+./package.use/20-service-bar -> ../stow/service-bar/package.use/20-service-bar
+./package.use/30-app-foo -> ../stow/app-foo/package.use/30-app-foo
+EOF
+
+have_links
+assert_output_matches "adds role 'host-baz'"
+
+want <<EOF
+bosun: this command requires at least one role
+EOF
+
+assert failure "add" "$BOSUN_CMD" add
+assert_output_matches "prints error message"
+
+want <<EOF
+bosun: no such role 'role-missing' in $BOSUN_DIR
+EOF
+
+assert failure "add role-missing" "$BOSUN_CMD" add role-missing
+assert_output_matches "prints error message"
+
+end
diff --git a/test/02-list.test b/test/02-list.test
new file mode 100644
index 0000000..075632e
--- /dev/null
+++ b/test/02-list.test
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+header "bosun list"
+
+want <<EOF
+app-foo
+service-bar
+EOF
+
+assert success "list active" "$BOSUN_CMD" list active
+assert_output_matches "lists active roles"
+
+assert success "list" "$BOSUN_CMD" list
+assert_output_matches "lists active roles"
+
+want <<EOF
+app-foo
+host-baz
+service-bar
+EOF
+
+assert success "list all" "$BOSUN_CMD" list all
+assert_output_matches "lists all roles"
+
+want <<EOF
+host-baz
+EOF
+
+assert success "list available" "$BOSUN_CMD" list available
+assert_output_matches "lists available roles"
+
+want <<EOF
+bosun: no such list type 'foo'. Try: active, all, available
+EOF
+
+assert failure "list foo" "$BOSUN_CMD" list foo
+assert_output_matches "prints error message"
+
+end
diff --git a/test/03-flush.test b/test/03-flush.test
new file mode 100644
index 0000000..435f534
--- /dev/null
+++ b/test/03-flush.test
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+header "bosun flush"
+
+assert success "flush" "$BOSUN_CMD" flush
+
+want <<EOF
+d .
+EOF
+
+have_dir
+assert_output_matches "no roles remaining"
+
+end
diff --git a/test/04-rebuild.test b/test/04-rebuild.test
new file mode 100644
index 0000000..503afc4
--- /dev/null
+++ b/test/04-rebuild.test
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+header "bosun rebuild"
+
+mkdir "$BOSUN_DIR/app-foo/package.accept_keywords" || exit 1
+touch "$BOSUN_DIR/app-foo/package.accept_keywords/30-app-foo" || exit 1
+
+assert success "rebuild app-foo" "$BOSUN_CMD" rebuild app-foo
+
+want <<EOF
+./package.accept_keywords/20-service-bar -> ../stow/service-bar/package.accept_keywords/20-service-bar
+./package.accept_keywords/30-app-foo -> ../stow/app-foo/package.accept_keywords/30-app-foo
+./package.use/20-service-bar -> ../stow/service-bar/package.use/20-service-bar
+./package.use/30-app-foo -> ../stow/app-foo/package.use/30-app-foo
+EOF
+
+have_links
+
+assert_output_matches "rebuilds role"
+
+end
diff --git a/test/05-remove.test b/test/05-remove.test
new file mode 100644
index 0000000..1fa7d35
--- /dev/null
+++ b/test/05-remove.test
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+header "bosun remove"
+
+assert success "remove app-foo" "$BOSUN_CMD" remove app-foo
+
+want <<EOF
+./package.accept_keywords -> stow/service-bar/package.accept_keywords
+./package.use -> stow/service-bar/package.use
+EOF
+
+have_links
+assert_output_matches "removes role"
+
+want <<EOF
+bosun: this command requires at least one role
+EOF
+
+assert failure "remove" "$BOSUN_CMD" remove
+assert_output_matches "prints error message"
+
+want <<EOF
+bosun: no such role 'role-missing' in $BOSUN_DIR
+EOF
+
+assert failure "remove role-missing" "$BOSUN_CMD" remove role-missing
+assert_output_matches "prints error message"
+
+end
diff --git a/test/06-default.test b/test/06-default.test
new file mode 100644
index 0000000..d40062e
--- /dev/null
+++ b/test/06-default.test
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+header "bosun"
+
+want <<EOF
+app-foo
+service-bar
+EOF
+
+assert success "bosun" "$BOSUN_CMD"
+assert_output_matches "lists active roles"
+
+want <<EOF
+bosun: no such command 'missing-command'
+usage: bosun add role ...
+ bosun flush
+ bosun [list [type ...]]
+ bosun rebuild [role ...]
+ bosun remove [role ...]
+EOF
+
+assert failure "missing-command" "$BOSUN_CMD" missing-command
+assert_output_matches "prints error message and usage"
+
+end
diff --git a/test/lib.sh b/test/lib.sh
new file mode 100644
index 0000000..733613c
--- /dev/null
+++ b/test/lib.sh
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+TESTS_FAILED=0
+
+ok() {
+ if ! test -t 1; then
+ printf 'ok - %s\n' "$*"
+ else
+ printf '\e[32mok\e[0m - %s\n' "$*"
+ fi
+}
+
+nok() {
+ TESTS_FAILED=$((TESTS_FAILED + 1))
+ if ! test -t 1; then
+ printf 'not ok - %s\n' "$*" >&2
+ else
+ printf '\e[31mnot ok\e[0m - %s\n' "$*" >&2
+ fi
+}
+
+header() {
+ printf '# %s\n' "$*"
+}
+
+info() {
+ printf '\n'
+ eval "$@"
+ printf '\n'
+}
+
+want() {
+ cat > want
+}
+
+assert_output_matches() {
+ msg=$1
+ if cmp have want >/dev/null 2>&1; then
+ ok "$msg"
+ return 0
+ else
+ nok "$msg"
+ info diff -u have want >&2
+ return 1
+ fi
+}
+
+assert() {
+ if test "$1" = "success"; then
+ assert_return=0
+ elif test "$1" = "failure"; then
+ assert_return=1
+ else
+ assert_return=$1
+ fi
+ shift
+
+ msg=$1
+ shift
+
+ eval "$@" > have 2>&1
+
+ if test "$?" -eq "$assert_return"; then
+ ok "$msg"
+ return 0
+ else
+ nok "$msg"
+ info cat have >&2
+ return 1
+ fi
+}
+
+end() {
+ test $TESTS_FAILED -gt 0 && exit $TESTS_FAILED
+ exit 0
+}
+
+have_dir() {
+ (cd "$BOSUN_DIR/.." && find . -printf '%y %p\n' | sed '/^..\.\/stow/d' | sort) > have
+}
+
+have_links() {
+ (cd "$BOSUN_DIR/.." && find . -type l -printf '%p -> %l\n' | sort) > have
+}
diff --git a/test/setup.sh b/test/setup.sh
new file mode 100644
index 0000000..636c7d6
--- /dev/null
+++ b/test/setup.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+mkdir -p "$BOSUN_DIR/app-foo/package.use"
+mkdir -p "$BOSUN_DIR/service-bar/package.use"
+mkdir -p "$BOSUN_DIR/service-bar/package.accept_keywords"
+mkdir -p "$BOSUN_DIR/host-baz"
+
+touch "$BOSUN_DIR/app-foo/package.use/30-app-foo"
+touch "$BOSUN_DIR/service-bar/package.use/20-service-bar"
+touch "$BOSUN_DIR/service-bar/package.accept_keywords/20-service-bar"
+touch "$BOSUN_DIR/host-baz/make.conf"
+
+mkdir -p "$BOSUN_DIR/../package.use"
+ln -s ../stow/app-foo/package.use/30-app-foo "$BOSUN_DIR/../package.use/30-app-foo"
+ln -s ../stow/service-bar/package.use/20-service-bar "$BOSUN_DIR/../package.use/20-service-bar"
+ln -s stow/service-bar/package.accept_keywords "$BOSUN_DIR/../package.accept_keywords"