From 46eb5762d853429f8e0fb9a4aaef195714172d94 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 5 Sep 2023 11:57:02 +0200 Subject: [PATCH] fix: overridable ABRA_DIR --- pkg/config/env.go | 5 ++--- tests/integration/dirs.bats | 32 ++++++++++++++++++++++---------- tests/integration/helpers.sh | 5 ++--- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/pkg/config/env.go b/pkg/config/env.go index c0358dbb..0874fb57 100644 --- a/pkg/config/env.go +++ b/pkg/config/env.go @@ -17,9 +17,8 @@ import ( // getBaseDir retrieves the Abra base directory. func getBaseDir() string { home := os.ExpandEnv("$HOME/.abra") - if _, exists := os.LookupEnv("ABRA_TEST"); exists { - home = os.ExpandEnv("$HOME/.abra_test") - logrus.Debugf("running under test mode as requested (ABRA_TEST)") + if customAbraDir, exists := os.LookupEnv("ABRA_DIR"); exists && customAbraDir != "" { + home = customAbraDir } return home } diff --git a/tests/integration/dirs.bats b/tests/integration/dirs.bats index bc326652..0ba86678 100644 --- a/tests/integration/dirs.bats +++ b/tests/integration/dirs.bats @@ -6,22 +6,34 @@ setup() { _setup_env } -@test "ensure abra directories created" { +@test "ABRA_DIR can be overriden" { + ABRA_DIR="$HOME/.abra_foo" + run $ABRA app ls # no servers yet, so will fail. however, it will run the required code which # checks if it should create these base directories and that is what we want assert_failure - assert [ -d "$ABRA_TEST_DIR" ] - assert [ -d "$ABRA_TEST_DIR/servers" ] - assert [ -d "$ABRA_TEST_DIR/recipes" ] - assert [ -d "$ABRA_TEST_DIR/backups" ] - assert [ -d "$ABRA_TEST_DIR/vendor" ] - assert [ -d "$ABRA_TEST_DIR/catalogue" ] + assert [ -d "$HOME/.abra_foo" ] } -@test "ensure catalogue recipe is a git repository" { +@test "abra directories created" { + run $ABRA app ls + + # no servers yet, so will fail. however, it will run the required code which + # checks if it should create these base directories and that is what we want + assert_failure + + assert [ -d "$ABRA_DIR" ] + assert [ -d "$ABRA_DIR/servers" ] + assert [ -d "$ABRA_DIR/recipes" ] + assert [ -d "$ABRA_DIR/backups" ] + assert [ -d "$ABRA_DIR/vendor" ] + assert [ -d "$ABRA_DIR/catalogue" ] +} + +@test "catalogue recipe is a git repository" { run $ABRA app ls # no servers yet, so will fail. however, it will run the required code which @@ -30,8 +42,8 @@ setup() { assert_output --partial 'local recipe catalogue is missing' - assert [ -d "$ABRA_TEST_DIR/catalogue" ] - assert [ -d "$ABRA_TEST_DIR/catalogue/.git" ] + assert [ -d "$ABRA_DIR/catalogue" ] + assert [ -d "$ABRA_DIR/catalogue/.git" ] } teardown(){ diff --git a/tests/integration/helpers.sh b/tests/integration/helpers.sh index e573b631..f3aa6ead 100644 --- a/tests/integration/helpers.sh +++ b/tests/integration/helpers.sh @@ -24,13 +24,12 @@ _setup_env(){ ABRA="$ROOT/abra" KADABRA="$ROOT/kadabra" - ABRA_TEST=true - ABRA_TEST_DIR="$HOME/.abra_test" + ABRA_DIR="$HOME/.abra_test" _build_abra _build_kadabra } _default_teardown(){ - rm -rf "$ABRA_TEST_DIR" + rm -rf "$ABRA_DIR" }