diff --git a/.github/workflows/stackql-assert-test.yml b/.github/workflows/stackql-assert-test.yml index e986037..d6d615b 100644 --- a/.github/workflows/stackql-assert-test.yml +++ b/.github/workflows/stackql-assert-test.yml @@ -33,11 +33,12 @@ jobs: uses: ./ with: test_query: | - SELECT name - FROM google.compute.instances - WHERE project = 'stackql-integration-tests' AND zone = 'australia-southeast1-a' and name = 'stackql-test-001'; + SELECT name, location, locationType + FROM google.storage.buckets + WHERE project = 'stackql' + AND name = 'stackql-public-releases'; expected_rows: 1 - env: + env: GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} # @@ -47,8 +48,8 @@ jobs: uses: ./ with: test_query_file_path: './.github/workflows/workflow_scripts/google-example.iql' - expected_results_str: '[{"name":"stackql-test-001"}]' - env: + expected_results_str: '[{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}]' + env: GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} # @@ -59,11 +60,9 @@ jobs: with: test_query_file_path: './.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql' expected_results_file_path: './.github/workflows/workflow_scripts/google-example-inline-jsonnet-results.json' - vars: GOOGLE_PROJECT=${{ env.GOOGLE_PROJECT }},GOOGLE_ZONE=${{ env.GOOGLE_ZONE }} - env: + vars: GOOGLE_PROJECT=stackql + env: GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} - GOOGLE_PROJECT: ${{ vars.GOOGLE_PROJECT }} - GOOGLE_ZONE: ${{ vars.GOOGLE_ZONE }} # # Example `test_query_file_path` with `expected_rows` supplying `vars` using `jsonnet` config provided using `data_file_path` diff --git a/.github/workflows/workflow_scripts/google-example-inline-jsonnet-results.json b/.github/workflows/workflow_scripts/google-example-inline-jsonnet-results.json index ed8d431..b6bd69d 100644 --- a/.github/workflows/workflow_scripts/google-example-inline-jsonnet-results.json +++ b/.github/workflows/workflow_scripts/google-example-inline-jsonnet-results.json @@ -1 +1 @@ -[{"name":"stackql-test-001"}] \ No newline at end of file +[{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}] diff --git a/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql b/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql index e42aade..b840d0b 100644 --- a/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql +++ b/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql @@ -1,11 +1,10 @@ <<>> -SELECT name -FROM google.compute.instances -WHERE project = '{{ .project }}' and zone = '{{ .zone }}' and name = 'stackql-test-001'; \ No newline at end of file +SELECT name, location, locationType +FROM google.storage.buckets +WHERE project = '{{ .project }}' +AND name = 'stackql-public-releases'; diff --git a/.github/workflows/workflow_scripts/google-example.iql b/.github/workflows/workflow_scripts/google-example.iql index acbed77..4b0b510 100644 --- a/.github/workflows/workflow_scripts/google-example.iql +++ b/.github/workflows/workflow_scripts/google-example.iql @@ -1,3 +1,4 @@ -SELECT name -FROM google.compute.instances -WHERE project = 'stackql-integration-tests' AND zone = 'australia-southeast1-a' AND name = 'stackql-test-001'; \ No newline at end of file +SELECT name, location, locationType +FROM google.storage.buckets +WHERE project = 'stackql' +AND name = 'stackql-public-releases'; diff --git a/lib/assert.js b/lib/assert.js index 7c7332e..8f8b126 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -20,6 +20,13 @@ const getExpectedResult = (expectedResultStr, expectedResultFilePath) => { return null; }; +const sortedStringify = (obj) => JSON.stringify(obj, Object.keys(obj).sort()); + +const rowsMatch = (expected, actual) => { + if (expected.length !== actual.length) return false; + return expected.every((expectedRow, i) => sortedStringify(expectedRow) === sortedStringify(actual[i])); +}; + const checkResult = (core, expected, actual, expectedRows) => { const actualLength = actual.length; @@ -28,7 +35,7 @@ const checkResult = (core, expected, actual, expectedRows) => { return false; } - if (expected && JSON.stringify(expected) !== JSON.stringify(actual)) { + if (expected && !rowsMatch(expected, actual)) { core.error(`Expected results do not match actual results.\nExpected: ${JSON.stringify(expected)}\nActual: ${JSON.stringify(actual)}`); return false; } diff --git a/lib/tests/assert.test.js b/lib/tests/assert.test.js index 0bd4ffb..9d5a34d 100644 --- a/lib/tests/assert.test.js +++ b/lib/tests/assert.test.js @@ -3,8 +3,8 @@ const {checkResult, parseResult, assertResult, getExpectedResult} = require('../ describe('parseResult', ()=>{ it('should parsedResult correctly', ()=>{ - const resultString = `[{"name":"stackql-demo-001","status":"TERMINATED"}]` - const expected = [{"name":"stackql-demo-001","status":"TERMINATED"}] + const resultString = `[{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}]` + const expected = [{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}] const actual = parseResult(resultString); expect(actual).toEqual(expected); }) @@ -12,8 +12,8 @@ describe('parseResult', ()=>{ describe('getExpectedResult', ()=>{ it('should return expectedResult when expectedResultStr is passed', ()=>{ - const expectedResultStr = `[{"name":"stackql-demo-001","status":"TERMINATED"}]` - const expectedResult = [{"name":"stackql-demo-001","status":"TERMINATED"}] + const expectedResultStr = `[{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}]` + const expectedResult = [{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}] const actual = getExpectedResult(expectedResultStr, undefined); @@ -22,7 +22,7 @@ describe('getExpectedResult', ()=>{ it('should return expectedResult when expectedResultFilePath is passed', ()=>{ const expectedResultFilePath = 'lib/tests/success-result.json' - const expectedResult = [{"name":"stackql-demo-001","status":"TERMINATED"}] + const expectedResult = [{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}] const actual = getExpectedResult(undefined, expectedResultFilePath); @@ -42,7 +42,7 @@ describe('checkResult', () => { core.info.mockClear(); core.error.mockClear(); core.setFailed.mockClear(); - }); + }); it('should return false and log an error when the actual length does not match expected rows', () => { const expectedRows = "3"; @@ -89,8 +89,8 @@ describe('assertResult', ()=>{ let coreObj; const ACTION_ENV = { - RESULT: `[{"name":"stackql-demo-001","status":"TERMINATED"}]`, - EXPECTED_RESULTS_STR: `[{"name":"stackql-demo-001","status":"TERMINATED"}]`, + RESULT: `[{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}]`, + EXPECTED_RESULTS_STR: `[{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}]`, EXPECTED_RESULTS_FILE_PATH: 'test.json', EXPECTED_ROWS: 1 } @@ -120,7 +120,7 @@ describe('assertResult', ()=>{ }); it('it should setFailed when actual result is not equal to expected result', () => { - process.env.RESULT= "[{\"name\":\"stackql-demo-001\",\"status\":\"RUNNING\"}]" + process.env.RESULT= "[{\"location\":\"EU\",\"locationType\":\"multi-region\",\"name\":\"stackql-public-releases\"}]" assertResult(coreObj) @@ -185,6 +185,6 @@ describe('assertResult', ()=>{ expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) }) - + }) diff --git a/lib/tests/failed-result.json b/lib/tests/failed-result.json index 82e6d31..f76fe22 100644 --- a/lib/tests/failed-result.json +++ b/lib/tests/failed-result.json @@ -1 +1 @@ -[{"name":"stackql-demo-001","status":"RUNNING"}] \ No newline at end of file +[{"location":"EU","locationType":"multi-region","name":"stackql-public-releases"}] diff --git a/lib/tests/success-result.json b/lib/tests/success-result.json index 030276f..b6bd69d 100644 --- a/lib/tests/success-result.json +++ b/lib/tests/success-result.json @@ -1 +1 @@ -[{"name":"stackql-demo-001","status":"TERMINATED"}] \ No newline at end of file +[{"location":"US","locationType":"multi-region","name":"stackql-public-releases"}]