From 67e80307707ca5517411abf36df1107d75111794 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 21 Nov 2014 23:07:53 +0100 Subject: [PATCH] tests: add and use test_autoenv_add_to_env and test_autoenv_auth_env_files Conflicts: autoenv.zsh --- autoenv.zsh | 5 +++++ tests/autoenv.t | 4 ++-- tests/cwd.t | 3 +-- tests/setup.sh | 12 ++++++++++++ tests/varstash.t | 3 +-- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/autoenv.zsh b/autoenv.zsh index 5be6c31..317217f 100644 --- a/autoenv.zsh +++ b/autoenv.zsh @@ -24,6 +24,11 @@ _dotenv_stack_entered=() _dotenv_hash_pair() { local env_file=$1 + if (( $+2 )); then + env_shasum=$2 + else + env_shasum=$(shasum $env_file | cut -d' ' -f1) + fi echo "$env_file:$env_shasum:1" } diff --git a/tests/autoenv.t b/tests/autoenv.t index 4750912..f477c13 100644 --- a/tests/autoenv.t +++ b/tests/autoenv.t @@ -6,7 +6,7 @@ Lets set a simple .env action Manually create auth file - $ echo "$PWD/.env:$(echo echo ENTERED | shasum)" > $AUTOENV_ENV_FILENAME + $ test_autoenv_add_to_env $PWD/.env $ cd . ENTERED @@ -41,7 +41,7 @@ Now lets see that it actually checks the shasum value $ unset _dotenv_stack_entered $ rm $AUTOENV_ENV_FILENAME - $ echo "$PWD/.env:$(echo mischief | shasum)" > $AUTOENV_ENV_FILENAME + $ test_autoenv_add_to_env $PWD/.env mischief $ cd . Attempting to load unauthorized env file: /tmp/cramtests-??????/autoenv.t/.env (glob) diff --git a/tests/cwd.t b/tests/cwd.t index 99f77fe..2c5838a 100644 --- a/tests/cwd.t +++ b/tests/cwd.t @@ -12,8 +12,7 @@ Setup env actions / output. Manually create auth files. - $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $AUTOENV_ENV_FILENAME - $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME + $ test_autoenv_auth_env_files The actual tests. diff --git a/tests/setup.sh b/tests/setup.sh index b2f5aaf..a7da1b4 100644 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -1,6 +1,18 @@ # Ensure we have our mocked out AUTOENV_ENV_FILENAME +# (via .zshenv). [[ $AUTOENV_ENV_FILENAME[0,4] == '/tmp' ]] || return 1 # Inject timeout for `read` while running tests. _AUTOENV_TEST_READ_ARGS='-t 1' + +test_autoenv_add_to_env() { + _dotenv_hash_pair $1 $2 >> $AUTOENV_ENV_FILENAME +} + +# Add enter and leave env files to authentication file. +test_autoenv_auth_env_files() { + echo -n > $AUTOENV_ENV_FILENAME + test_autoenv_add_to_env $PWD/$DOTENV_FILE_ENTER + test_autoenv_add_to_env $PWD/$DOTENV_FILE_LEAVE +} diff --git a/tests/varstash.t b/tests/varstash.t index bc49657..c6d33f0 100644 --- a/tests/varstash.t +++ b/tests/varstash.t @@ -16,8 +16,7 @@ Setup test environment. Manually create auth file - $ echo "$PWD/$DOTENV_FILE_ENTER:$(echo $(<$DOTENV_FILE_ENTER) | shasum)" > $AUTOENV_ENV_FILENAME - $ echo "$PWD/$DOTENV_FILE_LEAVE:$(echo $(<$DOTENV_FILE_LEAVE) | shasum)" >> $AUTOENV_ENV_FILENAME + $ test_autoenv_auth_env_files Set environment variable. -- 2.48.1