_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"
}
Manually create auth file
- $ echo "$PWD/.env:$(echo echo ENTERED | shasum)" > $AUTOENV_ENV_FILENAME
+ $ test_autoenv_add_to_env $PWD/.env
$ cd .
ENTERED
$ 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)
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.
# 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
+}
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.