-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/commands: support "schema test" (#20)
- Loading branch information
Showing
5 changed files
with
200 additions
and
8 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,53 @@ | ||
description: > | ||
This command test schema on a database. | ||
parameters: | ||
dev_url: | ||
type: string | ||
default: '' | ||
description: | | ||
The URL of the dev-database to use for analysis. For example: mysql://root:pass@localhost:3306/dev. | ||
Read more about [dev-databases](https://atlasgo.io/concepts/dev-database). | ||
url: | ||
type: string | ||
default: '' | ||
description: | | ||
The desired schema URL(s) to test. For Example: `file://schema.hcl` | ||
run: | ||
type: string | ||
default: '' | ||
description: | | ||
Filter tests to run by regexp. For example, `^test_.*` will only run tests that start with `test_`. Default is to run all tests. | ||
config: | ||
type: string | ||
default: '' | ||
description: | | ||
The path to the Atlas configuration file. By default, Atlas will look for a file named `atlas.hcl` in the current directory. | ||
For example, `file://config/atlas.hcl`. Learn more about [Atlas configuration files](https://atlasgo.io/atlas-schema/projects). | ||
vars: | ||
type: string | ||
default: '' | ||
description: | | ||
Extra variables to pass to the Atlas configuration file. For example, `key=value`. | ||
working_directory: | ||
type: string | ||
default: "." | ||
description: | | ||
The working directory to run from. Defaults to project root. | ||
env: | ||
type: string | ||
default: '' | ||
description: | | ||
The environment to use from the Atlas configuration file. For example, `dev`. | ||
steps: | ||
- run: | ||
name: Test schema on a database | ||
working_directory: <<parameters.working_directory>> | ||
command: atlasaction --action schema/test | ||
environment: | ||
INPUT_DEV_URL: <<parameters.dev_url>> | ||
INPUT_RUN: <<parameters.run>> | ||
INPUT_URL: <<parameters.url>> | ||
INPUT_CONFIG: <<parameters.config>> | ||
INPUT_ENV: <<parameters.env>> | ||
INPUT_VARS: <<parameters.vars>> |
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,12 @@ | ||
#!/bin/bash | ||
|
||
# execute the command and check the exit code is 1 | ||
# testing purpose only, use for integration tests | ||
atlasaction-origin --action schema/test | ||
if [ $? -ne 1 ]; then | ||
echo "Expected exit code 1, got $?" | ||
exit 1 | ||
else | ||
echo "Exit code 1 as expected" | ||
exit 0 | ||
fi |
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,8 @@ | ||
table "t1" { | ||
schema = schema.public | ||
column "c1" { | ||
type = int | ||
} | ||
} | ||
|
||
schema "public" {} |
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,13 @@ | ||
test "schema" "expected_success" { | ||
exec { | ||
sql = "select * from t1" | ||
output = "" | ||
} | ||
} | ||
|
||
test "schema" "expected_failure" { | ||
exec { | ||
sql = "select * from t1" | ||
output = "0" | ||
} | ||
} |