-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from jackwrfuller/feature/environment-variables
[Feature] Add support for env files
- Loading branch information
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Variables defined in this file should be accessible to all Ahoy commands, | ||
# since it is to be included in the 'global' environment variable. | ||
GLOBAL=global | ||
|
||
# This variable is to be overridden by the command-level env file, '.env.cmd'. | ||
TO_BE_OVERRIDDEN=before |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
COMMAND=123456789 | ||
TO_BE_OVERRIDDEN=after |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ahoyapi: v2 | ||
env: ./.env | ||
commands: | ||
test-global: | ||
cmd: echo $GLOBAL | ||
|
||
test-cmd: | ||
cmd: echo $COMMAND | ||
env: .env.cmd | ||
|
||
test-override: | ||
cmd: echo $TO_BE_OVERRIDDEN | ||
env: .env.cmd | ||
|
||
test-invalid-env: | ||
cmd: echo "This should not print!" | ||
env: .env.thisfiledoesntexist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "Command-level variables can be defined and used" { | ||
run ./ahoy -f testdata/env.ahoy.yml test-cmd | ||
[[ "$output" == "123456789" ]] | ||
} | ||
|
||
@test "Environment variables can be overriden" { | ||
run ./ahoy -f testdata/env.ahoy.yml test-override | ||
[[ "$output" = "after" ]] | ||
} | ||
|
||
@test "Global variables can be defined and used" { | ||
run ./ahoy -f testdata/env.ahoy.yml test-global | ||
[[ "$output" = "global" ]] | ||
} | ||
|
||
@test "Fail when attempting to load invalid env files" { | ||
run ./ahoy -f testdata/env.ahoy.yml test-invalid-env | ||
[ $status -eq 1 ] | ||
} |