Skip to content

Commit 192918b

Browse files
committed
Fix key-order-sensitive comparison and hardcode stable project var
assert.js: replace JSON.stringify deep equality with key-sorted comparison so JSON objects match regardless of key order. stackql-assert-test.yml: hardcode GOOGLE_PROJECT=stackql in the inline jsonnet test vars instead of pulling from the repo variable (which still pointed at stackql-integration-tests). https://claude.ai/code/session_019CH6RrcMGtdUafvyVCKCHE
1 parent 6b2050a commit 192918b

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

.github/workflows/stackql-assert-test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ jobs:
6060
with:
6161
test_query_file_path: './.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql'
6262
expected_results_file_path: './.github/workflows/workflow_scripts/google-example-inline-jsonnet-results.json'
63-
vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }}
63+
vars: GOOGLE_PROJECT=stackql
6464
env:
6565
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
66-
GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }}
6766

6867
#
6968
# Example `test_query_file_path` with `expected_rows` supplying `vars` using `jsonnet` config provided using `data_file_path`

lib/assert.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ const getExpectedResult = (expectedResultStr, expectedResultFilePath) => {
2020
return null;
2121
};
2222

23+
const sortedStringify = (obj) => JSON.stringify(obj, Object.keys(obj).sort());
24+
25+
const rowsMatch = (expected, actual) => {
26+
if (expected.length !== actual.length) return false;
27+
return expected.every((expectedRow, i) => sortedStringify(expectedRow) === sortedStringify(actual[i]));
28+
};
29+
2330
const checkResult = (core, expected, actual, expectedRows) => {
2431
const actualLength = actual.length;
2532

@@ -28,7 +35,7 @@ const checkResult = (core, expected, actual, expectedRows) => {
2835
return false;
2936
}
3037

31-
if (expected && JSON.stringify(expected) !== JSON.stringify(actual)) {
38+
if (expected && !rowsMatch(expected, actual)) {
3239
core.error(`Expected results do not match actual results.\nExpected: ${JSON.stringify(expected)}\nActual: ${JSON.stringify(actual)}`);
3340
return false;
3441
}

0 commit comments

Comments
 (0)