-
-
Notifications
You must be signed in to change notification settings - Fork 36
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 #121 from ahoy-cli/optional-imports
Add tests for the optional imports feature ( #119 )
- Loading branch information
Showing
15 changed files
with
236 additions
and
68 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
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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
ahoyapi: v2 | ||
commands: | ||
up: | ||
cmd: "docker-compose up -d" | ||
usage: Start the docker-compose containers. | ||
cmd: "docker compose up -d" | ||
usage: Start the Docker Compose containers. | ||
proxy-up: | ||
cmd: "docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy" | ||
usage: Run the nginx-proxy container | ||
stop: | ||
cmd: "docker-compose stop" | ||
usage: Stop the docker-compose containers (non-destructive). | ||
cmd: "docker compose stop" | ||
usage: Stop the Docker Compose containers (non-destructive). | ||
ps: | ||
cmd: "docker-compose ps" | ||
usage: List the running docker-compose containers. | ||
cmd: "docker compose ps" | ||
usage: List the running Docker Compose containers. | ||
ip: | ||
cmd: "docker-machine ip default" | ||
usage: Show the ip address f the default docker machine VM | ||
reset: | ||
cmd: "docker-compose stop && docker-compose rm && ahoy up" | ||
usage: Start the docker compose-containers. | ||
cmd: "docker compose stop && docker compose rm && ahoy up" | ||
usage: Start the Docker Compose containers. | ||
exec: | ||
cmd: docker exec -it $(docker-compose ps -q cli) bash -c "$@" | ||
usage: run a command in the docker-compose cli service container. | ||
cmd: docker exec -it $(docker compose ps -q cli) bash -c "$@" | ||
usage: run a command in the Docker Compose cli service container. | ||
mysql: | ||
cmd: "docker exec -it $(docker-compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
cmd: "docker exec -it $(docker compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
usage: Connect to the default mysql database. | ||
mysql-import: | ||
cmd: "docker exec -i $(docker-compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
cmd: "docker exec -i $(docker compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
usage: Pipe in a sql file. `ahoy mysql-import < backups/live.sql` | ||
mysql-dump: | ||
cmd: "docker exec -it $(docker-compose ps -q cli) bash -c 'mysqldump -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
cmd: "docker exec -it $(docker compose ps -q cli) bash -c 'mysqldump -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
usage: Dump data out into a file. `ahoy mysql-import > backups/local.sql` | ||
override-example: | ||
cmd: echo "Override me" |
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 |
---|---|---|
@@ -1,34 +1,31 @@ | ||
ahoyapi: v2 | ||
commands: | ||
up: | ||
cmd: "docker-compose up -d" | ||
usage: Start the docker-compose containers. | ||
cmd: "docker compose up -d" | ||
usage: Start the Docker Compose containers. | ||
proxy-up: | ||
cmd: "docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy" | ||
usage: Run the nginx-proxy container | ||
usage: Run the nginx-proxy container. | ||
stop: | ||
cmd: "docker-compose stop" | ||
usage: Stop the docker-compose containers (non-destructive). | ||
cmd: "docker compose stop" | ||
usage: Stop the Docker Compose containers (non-destructive). | ||
ps: | ||
cmd: "docker-compose ps" | ||
usage: List the running docker-compose containers. | ||
ip: | ||
cmd: "docker-machine ip default" | ||
usage: Show the ip address f the default docker machine VM | ||
cmd: "docker compose ps" | ||
usage: List the running Docker Compose containers. | ||
reset: | ||
cmd: "docker-compose stop && docker-compose rm && ahoy up" | ||
usage: Start the docker compose-containers. | ||
cmd: "docker compose stop && docker compose rm && ahoy up" | ||
usage: Start the Docker Compose containers. | ||
exec: | ||
cmd: docker exec -it $(docker-compose ps -q cli) bash -c "$@" | ||
usage: run a command in the docker-compose cli service container. | ||
cmd: docker exec -it $(docker compose ps -q cli) bash -c "$@" | ||
usage: Run a command in the Docker Compose cli service container. | ||
mysql: | ||
cmd: "docker exec -it $(docker-compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
cmd: "docker exec -it $(docker compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
usage: Connect to the default mysql database. | ||
mysql-import: | ||
cmd: "docker exec -i $(docker-compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
cmd: "docker exec -i $(docker compose ps -q cli) bash -c 'mysql -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
usage: Pipe in a sql file. `ahoy mysql-import < backups/live.sql` | ||
mysql-dump: | ||
cmd: "docker exec -it $(docker-compose ps -q cli) bash -c 'mysqldump -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
cmd: "docker exec -it $(docker compose ps -q cli) bash -c 'mysqldump -u$DB_ENV_MYSQL_USER -p$DB_ENV_MYSQL_PASSWORD -h$DB_PORT_3306_TCP_ADDR $DB_ENV_MYSQL_DATABASE'" | ||
usage: Dump data out into a file. `ahoy mysql-import > backups/local.sql` | ||
override-example: | ||
cmd: echo "Override me" |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
ahoyapi: v2 | ||
commands: | ||
missing-imports: | ||
usage: "This item has imports set, but it doesn't exit." | ||
usage: "This item has imports set, but it doesn't exist." | ||
imports: | ||
- "bogus.ahoy.yml" |
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 @@ | ||
ahoyapi: v2 | ||
commands: | ||
non-optional-cmd: | ||
usage: This command is not optional | ||
imports: | ||
- non-existent-file.yml |
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,10 @@ | ||
ahoyapi: v2 | ||
commands: | ||
optional-cmd: | ||
usage: These imports are optional | ||
imports: | ||
- testdata/non-existent-file.yml | ||
optional: true | ||
regular-cmd: | ||
usage: This is a regular command | ||
cmd: echo "This is a regular command" |
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
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "get the version of ahoy with --version" { | ||
@test "Get the version of ahoy with --version" { | ||
run ./ahoy -f testdata/simple.ahoy.yml --version | ||
[ $status -eq 0 ] | ||
[ $(expr "$output" : "^v?[0-9.]\.[0-9.]\.[0-9.](\S*)?") -eq 0 ] | ||
} | ||
|
||
@test "get help instead of running a command with --help" { | ||
@test "Get help instead of running a command with --help" { | ||
result="$(./ahoy -f testdata/simple.ahoy.yml --help echo something)" | ||
[ "$result" != "something" ] | ||
} |
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,42 @@ | ||
#!/usr/bin/env bats | ||
|
||
load 'test_helpers/bats-support/load' | ||
load 'test_helpers/bats-assert/load' | ||
|
||
@test "Optional import not found doesn't cause error" { | ||
# Run ahoy without arguments (which typically lists available commands) | ||
run ./ahoy -f testdata/optional-command.ahoy.yml | ||
|
||
# Check that the optional command is not listed | ||
[[ ! "$output" =~ "optional-cmd" ]] | ||
|
||
# Check that the regular command is listed | ||
[[ "$output" =~ "regular-cmd" ]] | ||
|
||
# Check that a standard "Missing argument" error is shown | ||
[[ "$output" =~ "Missing flag or argument" ]] | ||
|
||
# Check that the command exited with an error | ||
[ $status -eq 1 ] | ||
|
||
# Try to run the optional command (it should fail gracefully) | ||
run ./ahoy -f testdata/optional-command.ahoy.yml optional-cmd | ||
[ $status -eq 1 ] | ||
[[ "$output" =~ "Command not found for 'optional-cmd'" ]] | ||
|
||
# Run the regular command (it should work) | ||
run ./ahoy -f testdata/optional-command.ahoy.yml regular-cmd | ||
[ $status -eq 0 ] | ||
[[ "$output" = "This is a regular command" ]] | ||
} | ||
|
||
@test "Non-optional command with missing imports causes error" { | ||
# Run ahoy without arguments | ||
run ./ahoy -f testdata/non-optional-command.ahoy.yml | ||
|
||
# Check that the command failed | ||
[ $status -eq 1 ] | ||
|
||
# Check for the appropriate error message | ||
[[ "$output" =~ "Command [non-optional-cmd] has 'imports' set, but no commands were found" ]] | ||
} |
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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "display help text and fatal error when no arguments are passed." { | ||
@test "Display help text and fatal error when no arguments are passed." { | ||
run ./ahoy -f testdata/simple.ahoy.yml | ||
# Should throw an error. | ||
[ $status -ne 0 ] | ||
echo "$output" | ||
[ "${#lines[@]}" -gt 10 ] | ||
[ "${lines[-1]}" == "[fatal] Missing flag or argument." ] | ||
[ "${lines[-1]}" == "[warn] Missing flag or argument." ] | ||
} | ||
|
||
@test "run a simple ahoy command: echo" { | ||
@test "Run a simple ahoy command: echo" { | ||
result="$(./ahoy -f testdata/simple.ahoy.yml echo something)" | ||
[ "$result" == "something" ] | ||
} | ||
|
||
@test "run a simple ahoy command (ls -a) with an extra parameter (-l)" { | ||
@test "Run a simple ahoy command (ls -a) with an extra parameter (-l)" { | ||
run ./ahoy -f testdata/simple.ahoy.yml list -- -l | ||
[ "${#lines[@]}" -gt 13 ] | ||
} |
Oops, something went wrong.