From 3bce19d12d93f1b27e7d2f2acbef0926417d5390 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Wed, 10 Mar 2021 17:09:13 +0100 Subject: Add a first draft of the test suite The introduction of a test suite makes future changes easier to troubleshoot and verify. Whilst this is only a first draft, it should be stable enough to be used in normal development and should cover the entirety of bosun's functionality. --- test/01-add.test | 31 +++++++++++++++++++ test/02-list.test | 39 ++++++++++++++++++++++++ test/03-flush.test | 14 +++++++++ test/04-rebuild.test | 21 +++++++++++++ test/05-remove.test | 29 ++++++++++++++++++ test/06-default.test | 25 ++++++++++++++++ test/lib.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/setup.sh | 16 ++++++++++ 8 files changed, 259 insertions(+) create mode 100644 test/01-add.test create mode 100644 test/02-list.test create mode 100644 test/03-flush.test create mode 100644 test/04-rebuild.test create mode 100644 test/05-remove.test create mode 100644 test/06-default.test create mode 100644 test/lib.sh create mode 100644 test/setup.sh (limited to 'test') 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 < 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 < ../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 < stow/service-bar/package.accept_keywords +./package.use -> stow/service-bar/package.use +EOF + +have_links +assert_output_matches "removes role" + +want <&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" -- cgit v1.2.3-2-gb3c3