Skip to content

Commit

Permalink
dryrun to show rendered query
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyaven committed Sep 4, 2023
1 parent f4c6dd8 commit 3169e00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stackql-assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
#
# Example `test_query_file_path` with `expected_rows` supplying `vars` using `jsonnet` config provided using `data_file_path`
#
- name: Use test query string and expected results file, with auth object
- name: Use test query file with a jsonnet data file sourcing external vars and an expected row count
uses: ./
with:
test_query_file_path: './.github/workflows/workflow_scripts/github-example.iql'
Expand Down
10 changes: 6 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ inputs:
runs:
using: "composite"
steps:
- name: Check StackQL is installed and set output
- name: check if stackql is installed and set output
id: check-stackql
shell: bash
run: |
Expand All @@ -43,13 +43,14 @@ runs:
echo "stackql_installed=false" >> $GITHUB_OUTPUT
fi
- name: Setup StackQL
- name: setup stackql
uses: stackql/setup-stackql@v1.2.0
if: ${{steps.check-stackql.outputs.stackql_installed == 'false'}}
with:
use_wrapper: true

- name: Setup auth
- name: setup auth
if: (inputs.auth_obj_path != '') || (inputs.auth_str != '')
id: setup-auth
uses: actions/github-script@v6
with:
Expand Down Expand Up @@ -92,7 +93,8 @@ runs:
const {showStackQLQuery} = require(utilsPath)
showStackQLQuery(core)
env:
DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}}
# DRYRUN_RESULT: ${{steps.dryrun-query.outputs.stdout}}
DRYRUN_RESULT: ${{steps}}

- name: execute stackql command
id: exec-query
Expand Down
17 changes: 10 additions & 7 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const parseResult = (resultStr, varName) => {
const jsonObj = JSON.parse(jsonStr); // parse the JSON string into an object
return jsonObj;
} catch (error) {
throw(`Failed to parse ${varName} JSON
throw(`Failed to parse ${varName} JSON
\nvalue: ${resultStr}
\nerror: ${error}`);
}
Expand All @@ -34,18 +34,21 @@ const checkResult = (expectedResult, expectedRows, actualResult) => {
let equality;
let message;
expectedRows = parseInt(expectedRows);
const successMessage = `✅ StackQL Assert Successful`;
const failureMessage = `❌ StackQL Assert Failed`;

// if only passed expectedRows, check expectedRows
// if only passed expected result, only check expected result
// if both passed, check both
if (expectedRows) {
equality = actualResult.length === expectedRows;
if(equality) {
message = `============ StackQL Assert Successful (row count) ============ \n
message = `============ ${successMessage} (row count) ============ \n
Expected Number of Rows: ${expectedRows} \n
Actual Number of Rows: ${actualResult.length} \n
`;
} else {
message = `============ StackQL Assert Failed (row count) ============ \n
message = `============ ${failureMessage} (row count) ============ \n
Expected Number of Rows: ${expectedRows} \n
Actual Number of Rows: ${actualResult.length} \n
Execution Result: ${JSON.stringify(actualResult)} \n
Expand All @@ -56,9 +59,9 @@ const checkResult = (expectedResult, expectedRows, actualResult) => {
if (expectedResult) {
equality = JSON.stringify(expectedResult) === JSON.stringify(actualResult);
if(equality) {
message = `============ StackQL Assert Successful (expected results) ============`;
message = `============ ${successMessage} (expected results) ============`;
} else {
message = `============ StackQL Assert Failed (expected results) ============ \n
message = `============ ${failureMessage} (expected results) ============ \n
Expected: ${JSON.stringify(expectedResult)}\n
Actual: ${JSON.stringify(actualResult)}
`;
Expand All @@ -80,7 +83,7 @@ function checkParameters(expectedResultStr, expectedResultFilePath, expectedRows
.map(param => param.name)

if (missingParams.length === 3) {
const errorMessage = "Cannot find expected result, file path or expected rows";
const errorMessage = "Cannot find expected result, file path or expected rows";
throw errorMessage;
}
}
Expand Down Expand Up @@ -111,7 +114,7 @@ const assertResult = (coreObj) =>{
const actualResult = parseResult(execResultStr);

if (!actualResult) {
core.setFailed("No Output from executing query");
core.setFailed(`❌ No Output from executing query`);
}

const {equality, message} = checkResult(expectedResult, expectedRows, actualResult);
Expand Down

0 comments on commit 3169e00

Please sign in to comment.