|
1 | 1 | # stackql-assert
|
2 |
| -Runs a unit test with a command, comparing the expected output with the actual output. |
| 2 | + |
| 3 | +The `stackql/stackql-assert` action is a JavaScript action that sets up StackQL CLI in your GitHub Actions workflow by: |
| 4 | + |
| 5 | +- Downloading a latest Stackql CLI and adding it to the `PATH`. |
| 6 | +- Setup AUTH env var in the Github Action |
| 7 | + |
| 8 | +This action can be run on `ubuntu-latest`, `windows-latest`, and `macos-latest` GitHub Actions runners, and will install and expose the latest version of the `stackql` CLI on the runner environment. |
| 9 | + |
| 10 | +# Usage |
| 11 | + |
| 12 | +## AUTH |
| 13 | +> **Note** |
| 14 | +> stackql-assert action uses same auth setup as [stackql-exec](https://github.com/stackql/stackql-exec/blob/main/README.md) |
| 15 | +> [Learn more](https://stackql.io/docs/getting-started/authenticating) about authentication setup when running stackql |
| 16 | +
|
| 17 | +### Example auth string |
| 18 | +``` |
| 19 | +{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" }, |
| 20 | + "github": { "type": "basic", "credentialsenvvar": "STACKQL_GITHUB_CREDS" }} |
| 21 | +``` |
| 22 | +It can be passed with `auth_str` as a string, or stored in a file and pass filename to `auth-obj-path` |
| 23 | +- For "basic" auth, you need to set a environment variable with same name as the value of `credentialsenvvar` in the auth string for the Github Action step. You can use [Github Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) to store the value of the environment variable, and use env to pass it to the action. For example: |
| 24 | +``` |
| 25 | +env: |
| 26 | + STACKQL_GITHUB_CREDS: ${{ secrets.STACKQL_GITHUB_CREDS }} |
| 27 | +``` |
| 28 | +- For "service_account" auth, you need to store the credentials into a file; You can follow the example of `Prep Google Creds (bash)` step in the [example workflow](./.github/workflows/stackql-assert.yml) |
| 29 | + |
| 30 | +## Test Query |
| 31 | +- Use `test_query` or `test_query_path` to pass the test query to the action. The test query should be a valid StackQL query. The action will run the query and check if the result is empty or not. If the result is empty, the action will fail the step. |
| 32 | +- Either `test_query` or `test_query_path` is required. If both are provided, `test_query` will be used. |
| 33 | +- query example can be found in [example workflow](./.github/workflows/stackql-assert.yml) and [example .iql file](./.github/workflows/workflow_scripts) |
| 34 | + |
| 35 | +## Expected Result |
| 36 | +- Use `expected_results_str` or `expected_results_file_path` to pass the expected result to the action. The expected result should be a valid JSON object. The action will compare the result with the expected result. If the result is not the same as the expected result, the action will fail the step. |
| 37 | +- Either `expected_results_str` or `expected_results_file_path` is required. If both are provided, `expected_results_str` will be used. |
| 38 | +- Expected result example can be found in [example workflow](./.github/workflows/stackql-assert.yml) and [example .json file](./.github/workflows/workflow_scripts) |
| 39 | + |
| 40 | + |
| 41 | +## Input |
| 42 | +- `auth_obj_path` - Path to the auth object file. |
| 43 | +- `auth_str` - Auth string. |
| 44 | +- `test_query` - Test query to run (overrides test_query_path). |
| 45 | +- `test_query_path` - Path to the test query file. |
| 46 | +- `expected_rows` - Expected number of rows in the result. |
| 47 | +- `expected_results_str` - expected result from executing test query, support object string (overrides expected_results_file_path) |
| 48 | +- `expected_results_file_path` - file that stores expected result, json is support |
0 commit comments