From 2daf5a01df97a677d117012b0347090d7feae27a Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Mon, 29 Apr 2024 11:04:13 +1000 Subject: [PATCH 1/5] remove unused --- lib/tests/assert.test.js | 207 --------------------------------------- lib/tests/test-auth.json | 1 - lib/tests/utils.test.js | 79 --------------- lib/utils.js | 124 ----------------------- stackql-assert.js | 4 - 5 files changed, 415 deletions(-) delete mode 100644 lib/tests/assert.test.js delete mode 100644 lib/tests/test-auth.json delete mode 100644 lib/tests/utils.test.js delete mode 100644 lib/utils.js delete mode 100644 stackql-assert.js diff --git a/lib/tests/assert.test.js b/lib/tests/assert.test.js deleted file mode 100644 index b9841c9..0000000 --- a/lib/tests/assert.test.js +++ /dev/null @@ -1,207 +0,0 @@ -const {checkResult, parseResult, assertResult, getExpectedResult} = require('../assert') - -describe('parseResult', ()=>{ - - it('should parsedResult correctly when it starts with register', ()=>{ - const resultString = `google provider, version 'v23.01.00116' successfully installed \n - [{"name":"stackql-demo-001","status":"TERMINATED"}]` - - const expected = [{"name":"stackql-demo-001","status":"TERMINATED"}] - - const actual = parseResult(resultString); - expect(actual).toEqual(expected); - }) - - it('should parsedResult correctly when it is only the object', ()=>{ - const resultString = `[{"name":"stackql-demo-001","status":"TERMINATED"}]` - - const expected = [{"name":"stackql-demo-001","status":"TERMINATED"}] - - const actual = parseResult(resultString); - expect(actual).toEqual(expected); - }) -}) - -describe('checkResult', ()=>{ - let expectedResult; - let actualResult; - beforeEach(()=>{ - expectedResult= [{"name":"stackql-demo-001","status":"TERMINATED"}] - actualResult= [{"name":"stackql-demo-001","status":"TERMINATED"}] - - }) - it('should return equality false when the result object does not match', ()=>{ - actualResult = [{"name":"stackql-demo-001","status":"RUNNING"}] - - const {equality} = checkResult(expectedResult, undefined, actualResult); - - expect(equality).toEqual(false); - }) - - it('should return equality true when the result object does match', ()=>{ - - const {equality} = checkResult(expectedResult, undefined, actualResult); - - expect(equality).toEqual(true); - }) - - it('should return equality false when expected row is not matching', ()=>{ - - const expectedRows = 2; - - const {equality} = checkResult(undefined, expectedRows, actualResult); - - expect(equality).toEqual(false); - }) - - it('should return equality true when expected row is matching', ()=>{ - const expectedRows = 1; - - const {equality} = checkResult(undefined, expectedRows, actualResult); - - expect(equality).toEqual(true); - }) - - it('should return equality false when expected row is matching, but result object does not match', ()=>{ - const expectedRows = 1; - actualResult = [{"name":"stackql-demo-001","status":"RUNNING"}] - - const {equality} = checkResult(expectedResult, expectedRows, actualResult); - - expect(equality).toEqual(false); - }) - - it('should return equality true when expected row is matching, but result object matches', ()=>{ - const expectedRows = 1; - actualResult = [{"name":"stackql-demo-001","status":"TERMINATED"}] - - const {equality} = checkResult(expectedResult, expectedRows, actualResult); - - expect(equality).toEqual(true); - }) -}) - -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 actual = getExpectedResult(expectedResultStr, undefined); - - expect(actual).toEqual(expectedResult); - }) - - it('should return expectedResult when expectedResultFilePath is passed', ()=>{ - const expectedResultFilePath = 'lib/tests/success-result.json' - const expectedResult = [{"name":"stackql-demo-001","status":"TERMINATED"}] - - const actual = getExpectedResult(undefined, expectedResultFilePath); - - expect(actual).toEqual(expectedResult); - }) - -}) - - describe('assertResult integration test', ()=>{ - let coreObj; - - const ACTION_ENV = { - RESULT: `google provider, version 'v23.01.00116' successfully installed \n - [{"name":"stackql-demo-001","status":"TERMINATED"}]`, - EXPECTED_RESULTS_STR: `[{"name":"stackql-demo-001","status":"TERMINATED"}]`, - EXPECTED_RESULTS_FILE_PATH: 'test.json', - EXPECTED_ROWS: 1 - } - - beforeEach(() => { - jest.resetModules() - process.env = {...ACTION_ENV} - coreObj = { - setFailed: jest.fn(), - info: jest.fn().mockImplementation((message)=>{console.log(message)}) - } - }) - afterEach(() => { - process.env = ACTION_ENV - }) - - - it('it should setFailed when there is expected results are undefined', () => { - process.env.EXPECTED_RESULTS_FILE_PATH = undefined - process.env.EXPECTED_RESULTS_STR = undefined - process.env.EXPECTED_ROWS = undefined - - assertResult(coreObj) - - expect(coreObj.setFailed).toHaveBeenCalledWith('āŒ Cannot find expected result, file path or expected rows') - }); - - it('it should setFailed when actual result is not equal to expected result', () => { - process.env.RESULT= "[{\"name\":\"stackql-demo-001\",\"status\":\"RUNNING\"}]" - - assertResult(coreObj) - - expect(coreObj.setFailed).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Failed')) - }); - - it('it should not setFailed when actual result equal to expected result', () => { - assertResult(coreObj) - - expect(coreObj.setFailed).not.toHaveBeenCalled() - expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) - }); - - it('it should setFailed when actual result is not equal to expected result', () => { - process.env.EXPECTED_RESULTS_STR= undefined; - process.env.EXPECTED_RESULTS_FILE_PATH = 'lib/tests/failed-result.json' - - assertResult(coreObj) - - expect(coreObj.setFailed).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Failed')) - }); - - it('it should not setFailed when actual result equal to expected result in file', () => { - process.env.EXPECTED_RESULTS_STR= undefined; - process.env.EXPECTED_RESULTS_FILE_PATH = 'lib/tests/success-result.json' - - assertResult(coreObj) - - expect(coreObj.setFailed).not.toHaveBeenCalled() - expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) - }) - - it('it should setFailed when actual result does not match expected rows', () => { - process.env.EXPECTED_RESULTS_STR= undefined; - process.env.EXPECTED_RESULTS_FILE_PATH = undefined; - process.env.EXPECTED_ROWS = 2 - - assertResult(coreObj) - - expect(coreObj.setFailed).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Failed')) - }); - - it('it should not setFailed when actual result match expected rows', ()=>{ - process.env.EXPECTED_RESULTS_STR= undefined; - process.env.EXPECTED_RESULTS_FILE_PATH = undefined; - process.env.EXPECTED_ROWS = 1 - - assertResult(coreObj) - - expect(coreObj.setFailed).not.toHaveBeenCalled() - expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) - }) - - it('it should not setFailed when actual result match expected rows in string number', ()=>{ - process.env.EXPECTED_RESULTS_STR= undefined; - process.env.EXPECTED_RESULTS_FILE_PATH = undefined; - process.env.EXPECTED_ROWS = '1' - - assertResult(coreObj) - - expect(coreObj.setFailed).not.toHaveBeenCalled() - expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) - }) - - - - }) diff --git a/lib/tests/test-auth.json b/lib/tests/test-auth.json deleted file mode 100644 index d8de066..0000000 --- a/lib/tests/test-auth.json +++ /dev/null @@ -1 +0,0 @@ -{ "google": { "type": "service_account", "credentialsfilepath": "sa-key.json" }} \ No newline at end of file diff --git a/lib/tests/utils.test.js b/lib/tests/utils.test.js deleted file mode 100644 index ab73fb7..0000000 --- a/lib/tests/utils.test.js +++ /dev/null @@ -1,79 +0,0 @@ -const { assertResult, parseResult, getExpectedResult } = require('./assert'); -const fs = require('fs'); - -jest.mock('fs'); - -describe('assert.js functions', () => { - let core; - - beforeEach(() => { - core = { - info: jest.fn(), - error: jest.fn(), - setFailed: jest.fn() - }; - process.env.RESULT = JSON.stringify([{ id: 1, value: 'test' }]); - process.env.EXPECTED_ROWS = '1'; - }); - - afterEach(() => { - jest.resetAllMocks(); - jest.restoreAllMocks(); - }); - - describe('parseResult', () => { - it('should correctly parse valid JSON', () => { - const input = JSON.stringify({ key: 'value' }); - expect(parseResult(input, 'valid JSON')).toEqual({ key: 'value' }); - }); - - it('should throw an error on invalid JSON', () => { - const input = "invalid JSON"; - expect(() => parseResult(input, 'invalid JSON')).toThrow('Failed to parse invalid JSON JSON'); - }); - }); - - describe('getExpectedResult', () => { - it('should return parsed result from string', () => { - const input = JSON.stringify({ key: 'value' }); - expect(getExpectedResult(input, null)).toEqual({ key: 'value' }); - }); - - it('should return parsed result from file', () => { - const input = JSON.stringify({ key: 'value' }); - fs.readFileSync.mockReturnValue(input); - expect(getExpectedResult(null, 'path/to/file')).toEqual({ key: 'value' }); - expect(fs.readFileSync).toHaveBeenCalledWith('path/to/file', 'utf-8'); - }); - - it('should throw an error if no input is provided', () => { - expect(() => getExpectedResult(null, null)).toThrow('No expected result provided.'); - }); - }); - - describe('assertResult', () => { - it('should log success if the expected rows and results match', () => { - process.env.EXPECTED_RESULTS_STR = process.env.RESULT; - assertResult(core); - expect(core.info).toHaveBeenCalledWith("āœ… StackQL Assert Successful"); - }); - - it('should fail if expected rows do not match', () => { - process.env.EXPECTED_ROWS = '2'; // Actual result will have only one item - assertResult(core); - expect(core.setFailed).toHaveBeenCalledWith(expect.stringContaining("Expected rows: 2, got: 1")); - }); - - it('should fail if expected results do not match', () => { - process.env.EXPECTED_RESULTS_STR = JSON.stringify([{ id: 1, value: 'wrong' }]); - assertResult(core); - expect(core.setFailed).toHaveBeenCalledWith(expect.stringContaining("Expected results do not match actual results.")); - }); - - it('should handle errors during processing', () => { - process.env.RESULT = 'invalid json'; - assertResult(core); - expect(core.setFailed).toHaveBeenCalledWith(expect.stringContaining("Assertion error")); - }); - }); -}); diff --git a/lib/utils.js b/lib/utils.js deleted file mode 100644 index 0a6f4b0..0000000 --- a/lib/utils.js +++ /dev/null @@ -1,124 +0,0 @@ -const fs = require("fs"); - -function setupAuth(core) { - let auth; - const fileName = process.env.AUTH_FILE_PATH; - const authStr = process.env.AUTH_STR; - - if (!checkEnvVarValid(fileName) && !checkEnvVarValid(authStr)) { - // core.info("Neither AUTH_FILE_PATH nor AUTH_STR is set. Proceeding using default provider environment variable names."); - return; - } - - if (checkEnvVarValid(fileName)) { - try { - // Read the contents of the JSON file into a string - auth = fs.readFileSync(fileName, "utf-8"); - } catch (error) { - core.error(error); - core.setFailed(`Cannot find auth file ${fileName}`); - return; - } - } - if (checkEnvVarValid(authStr)) { - auth = authStr - } - - core.info("Setting AUTH environment variable..."); - core.exportVariable("AUTH", auth); -} - -async function showStackQLQuery(core) { - try { - let [ - dryRunCommand, - dryRunResult, - ] = [ - process.env.STACKQL_DRYRUN_COMMAND, - process.env.DRYRUN_RESULT, - ]; - - if (!dryRunResult) { - core.setFailed("No Dryrun Output from stackql command"); - } - - core.info(`\nšŸš€ rendered stackql query:\n${dryRunResult}`); - - } catch (e) { - core.setFailed(e); - } -} - -async function getStackqlCommand(core) { - - const [query, queryFilePath, dataFilePath, vars, auth, output = "json"] = [ - process.env.QUERY, - process.env.QUERY_FILE_PATH, - process.env.DATA_FILE_PATH, - process.env.VARS, - process.env.AUTH, - process.env.OUTPUT, - ]; - - if (!checkEnvVarValid(query) && !checkEnvVarValid(queryFilePath)) { - core.setFailed("Either test_query or test_query_file_path need to be set"); - return; - } - - let args = ["exec"]; - let dryRunArgs = ["exec", "-H"]; - - if (query) { - args.push(`"${query}"`); - dryRunArgs.push(`"${query}"`); - } else { - args.push("-i", queryFilePath); - dryRunArgs.push("-i", queryFilePath); - } - - if (checkEnvVarValid(dataFilePath)) { - args.push(`--iqldata='${dataFilePath}'`); - dryRunArgs.push(`--iqldata='${dataFilePath}'`); - } - - if (checkEnvVarValid(vars)) { - args.push(`--var='${vars}'`); - dryRunArgs.push(`--var='${vars}'`); - } - - if (checkEnvVarValid(auth)) { - args.push(`--auth='${auth}'`); - dryRunArgs.push(`--auth='${auth}'`); - } - - args.push(`--output='${output}'`); - dryRunArgs.push(`--output='text'`); - dryRunArgs.push(`--dryrun`); - - try { - const stackqlQuery = `stackql ${args.join(" ")}`; - const stackqlDryRunQuery = `stackql ${dryRunArgs.join(" ")}`; - core.exportVariable('STACKQL_COMMAND', stackqlQuery); - core.exportVariable('STACKQL_DRYRUN_COMMAND', stackqlDryRunQuery); - } catch (error) { - core.error(error); - core.setFailed("Error exporting stackql command"); - } -} - -/** - * Checking if environment variable is not empty or undefined - * @param {*} variable - */ -const checkEnvVarValid = (variable) => { - if (!variable || variable === "" || variable === "undefined") { - return false; - } - return true; -}; - -module.exports = { - setupAuth, - getStackqlCommand, - showStackQLQuery, -}; diff --git a/stackql-assert.js b/stackql-assert.js deleted file mode 100644 index 9793059..0000000 --- a/stackql-assert.js +++ /dev/null @@ -1,4 +0,0 @@ -const { assertResult } = require('./lib/assert') -module.exports ={ - assertResult -} \ No newline at end of file From 40089a034578ddc5975509d865636d977b8d1a40 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Mon, 29 Apr 2024 11:55:17 +1000 Subject: [PATCH 2/5] fixed tests --- .github/workflows/npm-test.yml | 18 ++++ lib/assert.js | 10 +- lib/tests/assert.test.js | 190 +++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/npm-test.yml create mode 100644 lib/tests/assert.test.js diff --git a/.github/workflows/npm-test.yml b/.github/workflows/npm-test.yml new file mode 100644 index 0000000..9265d38 --- /dev/null +++ b/.github/workflows/npm-test.yml @@ -0,0 +1,18 @@ +name: 'npm test' +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4.1.4 + - name: Use Node.js 16 + uses: actions/setup-node@v4.0.2 + with: + node-version: 16.x + - run: npm ci + - run: npm test + \ No newline at end of file diff --git a/lib/assert.js b/lib/assert.js index f82946a..7c7332e 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -46,6 +46,9 @@ function assertResult(core) { if (!RESULT) throw new Error("Result from StackQL execution is missing."); + // if no EXPECTED_RESULTS_STR, EXPECTED_RESULTS_FILE_PATH or EXPECTED_ROWS, fail the action + if (!EXPECTED_RESULTS_STR && !EXPECTED_RESULTS_FILE_PATH && !EXPECTED_ROWS) throw new Error("āŒ Cannot find expected result, file path or expected rows"); + const actualResult = parseResult(RESULT); core.info("šŸ” Checking results..."); @@ -64,4 +67,9 @@ function assertResult(core) { } } -module.exports = { assertResult }; +module.exports = { + parseResult, + getExpectedResult, + checkResult, + assertResult +}; diff --git a/lib/tests/assert.test.js b/lib/tests/assert.test.js new file mode 100644 index 0000000..0bd4ffb --- /dev/null +++ b/lib/tests/assert.test.js @@ -0,0 +1,190 @@ +const {checkResult, parseResult, assertResult, getExpectedResult} = require('../assert') + +describe('parseResult', ()=>{ + + it('should parsedResult correctly', ()=>{ + const resultString = `[{"name":"stackql-demo-001","status":"TERMINATED"}]` + const expected = [{"name":"stackql-demo-001","status":"TERMINATED"}] + const actual = parseResult(resultString); + expect(actual).toEqual(expected); + }) +}) + +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 actual = getExpectedResult(expectedResultStr, undefined); + + expect(actual).toEqual(expectedResult); + }) + + it('should return expectedResult when expectedResultFilePath is passed', ()=>{ + const expectedResultFilePath = 'lib/tests/success-result.json' + const expectedResult = [{"name":"stackql-demo-001","status":"TERMINATED"}] + + const actual = getExpectedResult(undefined, expectedResultFilePath); + + expect(actual).toEqual(expectedResult); + }) + +}) + +describe('checkResult', () => { + const core = { + info: jest.fn(), + error: jest.fn(), + setFailed: jest.fn() + }; + + beforeEach(() => { + 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"; + const actualResult = [{}, {}, {}, {}]; // 4 items, should not match expectedRows + + const result = checkResult(core, undefined, actualResult, expectedRows); + + expect(result).toBe(false); + expect(core.error).toHaveBeenCalledWith(`Expected rows: ${expectedRows}, got: ${actualResult.length}`); + }); + + it('should return true when the actual length matches expected rows', () => { + const expectedRows = "2"; + const actualResult = [{}, {}]; // 2 items, matches expectedRows + + const result = checkResult(core, undefined, actualResult, expectedRows); + + expect(result).toBe(true); + expect(core.error).not.toHaveBeenCalled(); + }); + + it('should return false and log an error when expected does not match actual and expectedRows is undefined', () => { + const expected = [{ name: "test1" }, { name: "test2" }]; + const actual = [{ name: "test1" }, { name: "test3" }]; + + const result = checkResult(core, expected, actual, undefined); + + expect(result).toBe(false); + expect(core.error).toHaveBeenCalledWith(`Expected results do not match actual results.\nExpected: ${JSON.stringify(expected)}\nActual: ${JSON.stringify(actual)}`); + }); + + it('should return true when expected matches actual and expectedRows is undefined', () => { + const expected = [{ name: "test1" }, { name: "test2" }]; + const actual = [{ name: "test1" }, { name: "test2" }]; + + const result = checkResult(core, expected, actual, undefined); + + expect(result).toBe(true); + expect(core.error).not.toHaveBeenCalled(); + }); +}); + +describe('assertResult', ()=>{ + let coreObj; + + const ACTION_ENV = { + RESULT: `[{"name":"stackql-demo-001","status":"TERMINATED"}]`, + EXPECTED_RESULTS_STR: `[{"name":"stackql-demo-001","status":"TERMINATED"}]`, + EXPECTED_RESULTS_FILE_PATH: 'test.json', + EXPECTED_ROWS: 1 + } + + beforeEach(() => { + jest.resetModules() + process.env = {...ACTION_ENV} + coreObj = { + setFailed: jest.fn(), + info: jest.fn(), + error: jest.fn(), + } + }) + afterEach(() => { + process.env = ACTION_ENV + }) + + + it('it should setFailed when there is expected results are undefined', () => { + process.env.EXPECTED_RESULTS_FILE_PATH = undefined + process.env.EXPECTED_RESULTS_STR = undefined + process.env.EXPECTED_ROWS = undefined + + assertResult(coreObj) + + expect(coreObj.setFailed).toHaveBeenCalledWith('Assertion error: āŒ Cannot find expected result, file path or expected rows') + }); + + it('it should setFailed when actual result is not equal to expected result', () => { + process.env.RESULT= "[{\"name\":\"stackql-demo-001\",\"status\":\"RUNNING\"}]" + + assertResult(coreObj) + + expect(coreObj.setFailed).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Failed')) + }); + + it('it should not setFailed when actual result equal to expected result', () => { + assertResult(coreObj) + + expect(coreObj.setFailed).not.toHaveBeenCalled() + expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) + }); + + it('it should setFailed when actual result is not equal to expected result', () => { + process.env.EXPECTED_RESULTS_STR= undefined; + process.env.EXPECTED_RESULTS_FILE_PATH = 'lib/tests/failed-result.json' + + assertResult(coreObj) + + expect(coreObj.setFailed).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Failed')) + }); + + it('it should not setFailed when actual result equal to expected result in file', () => { + process.env.EXPECTED_RESULTS_STR= undefined; + process.env.EXPECTED_RESULTS_FILE_PATH = 'lib/tests/success-result.json' + + assertResult(coreObj) + + expect(coreObj.setFailed).not.toHaveBeenCalled() + expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) + }) + + it('it should setFailed when actual result does not match expected rows', () => { + process.env.EXPECTED_RESULTS_STR= undefined; + process.env.EXPECTED_RESULTS_FILE_PATH = undefined; + process.env.EXPECTED_ROWS = 2 + + assertResult(coreObj) + + expect(coreObj.setFailed).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Failed')) + }); + + it('it should not setFailed when actual result match expected rows', ()=>{ + process.env.EXPECTED_RESULTS_STR= undefined; + process.env.EXPECTED_RESULTS_FILE_PATH = undefined; + process.env.EXPECTED_ROWS = 1 + + assertResult(coreObj) + + expect(coreObj.setFailed).not.toHaveBeenCalled() + expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) + }) + + it('it should not setFailed when actual result match expected rows in string number', ()=>{ + process.env.EXPECTED_RESULTS_STR= undefined; + process.env.EXPECTED_RESULTS_FILE_PATH = undefined; + process.env.EXPECTED_ROWS = '1' + + assertResult(coreObj) + + expect(coreObj.setFailed).not.toHaveBeenCalled() + expect(coreObj.info).toHaveBeenCalledWith(expect.stringContaining('StackQL Assert Successful')) + }) + + + +}) From 55776d01d670e361f5dcd2539f3f03fce9394b4b Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Mon, 29 Apr 2024 11:56:47 +1000 Subject: [PATCH 3/5] fixed tests --- .github/workflows/npm-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/npm-test.yml b/.github/workflows/npm-test.yml index 9265d38..5d2106f 100644 --- a/.github/workflows/npm-test.yml +++ b/.github/workflows/npm-test.yml @@ -1,6 +1,5 @@ name: 'npm test' on: - push: pull_request: jobs: @@ -8,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4.1.4 + - uses: actions/checkout@v4.1.3 - name: Use Node.js 16 uses: actions/setup-node@v4.0.2 with: From df54929819a6e8434cab94e9afa283dc5ea084d3 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 29 Oct 2024 08:30:21 +1100 Subject: [PATCH 4/5] name change --- README.md | 2 +- action.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 46322cc..4a4616d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The `stackql/stackql-assert` action is an composite action that runs a `stackql` # Usage -> This action uses the [setup-stackql](https://github.com/marketplace/actions/stackql-studios-setup-stackql) and [stackql-exec](https://github.com/marketplace/actions/stackql-studios-stackql-exec) actions +> This action uses the [setup-stackql](https://github.com/marketplace/actions/setup-stackql) and [stackql-exec](https://github.com/marketplace/actions/stackql-exec) actions ## Provider Authentication Authentication to StackQL providers is done via environment variables source from GitHub Actions Secrets. To learn more about authentication, see the setup instructions for your provider or providers at the [StackQL Provider Registry Docs](https://stackql.io/registry). diff --git a/action.yml b/action.yml index 4d31e12..5f12609 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: 'StackQL Studios - StackQL Assert' +name: 'stackql-assert' description: 'Run StackQL query to test and audit your infrastructure.' author: 'Yuncheng Yang, StackQL Studios' inputs: @@ -66,4 +66,4 @@ runs: branding: icon: 'terminal' - color: 'green' + color: 'blue' From 72d1189c96b1c63553ca38ab0c554101fb7c96d4 Mon Sep 17 00:00:00 2001 From: Jeffrey Aven Date: Tue, 29 Oct 2024 11:00:23 +1100 Subject: [PATCH 5/5] updated tests --- .github/workflows/npm-test.yml | 9 ++++----- .github/workflows/stackql-assert-test.yml | 6 +++--- .../google-example-inline-jsonnet-results.json | 2 +- .../workflow_scripts/google-example-inline-jsonnet.iql | 2 +- .github/workflows/workflow_scripts/google-example.iql | 2 +- action.yml | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/npm-test.yml b/.github/workflows/npm-test.yml index 5d2106f..c5337b4 100644 --- a/.github/workflows/npm-test.yml +++ b/.github/workflows/npm-test.yml @@ -8,10 +8,9 @@ jobs: steps: - uses: actions/checkout@v4.1.3 - - name: Use Node.js 16 - uses: actions/setup-node@v4.0.2 + - name: Setup Node.js environment + uses: actions/setup-node@v4.1.0 with: - node-version: 16.x + node-version: 18 - run: npm ci - - run: npm test - \ No newline at end of file + - run: npm test \ No newline at end of file diff --git a/.github/workflows/stackql-assert-test.yml b/.github/workflows/stackql-assert-test.yml index a7615e3..eaf6851 100644 --- a/.github/workflows/stackql-assert-test.yml +++ b/.github/workflows/stackql-assert-test.yml @@ -21,7 +21,7 @@ jobs: # Pull required providers # - name: pull required providers - uses: stackql/stackql-exec@v2.2.1 + uses: stackql/stackql-exec@v2.2.3 with: is_command: true query: "REGISTRY PULL google; REGISTRY PULL github" @@ -35,7 +35,7 @@ jobs: test_query: | SELECT name FROM google.compute.instances - WHERE project = 'stackql-demo' AND zone = 'australia-southeast1-a' AND name = 'stackql-demo-001'; + WHERE project = 'stackql-integration-tests' AND zone = 'australia-southeast1-a' and name = 'stackql-test-001'; expected_rows: 1 env: GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} @@ -47,7 +47,7 @@ jobs: uses: ./ with: test_query_file_path: './.github/workflows/workflow_scripts/google-example.iql' - expected_results_str: '[{"name":"stackql-demo-001"}]' + expected_results_str: '[{"name":"stackql-test-001"}]' env: GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }} 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 8f652aa..ed8d431 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-demo-001"}] \ No newline at end of file +[{"name":"stackql-test-001"}] \ No newline at end of file diff --git a/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql b/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql index bceabe0..e42aade 100644 --- a/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql +++ b/.github/workflows/workflow_scripts/google-example-inline-jsonnet.iql @@ -8,4 +8,4 @@ local zone = std.extVar("GOOGLE_ZONE"); >>> SELECT name FROM google.compute.instances -WHERE project = '{{ .project }}' and zone = '{{ .zone }}' and name = 'stackql-demo-001'; \ No newline at end of file +WHERE project = '{{ .project }}' and zone = '{{ .zone }}' and name = 'stackql-test-001'; \ No newline at end of file diff --git a/.github/workflows/workflow_scripts/google-example.iql b/.github/workflows/workflow_scripts/google-example.iql index a10d1cf..acbed77 100644 --- a/.github/workflows/workflow_scripts/google-example.iql +++ b/.github/workflows/workflow_scripts/google-example.iql @@ -1,3 +1,3 @@ SELECT name FROM google.compute.instances -WHERE project = 'stackql-demo' AND zone = 'australia-southeast1-a' AND name = 'stackql-demo-001'; \ No newline at end of file +WHERE project = 'stackql-integration-tests' AND zone = 'australia-southeast1-a' AND name = 'stackql-test-001'; \ No newline at end of file diff --git a/action.yml b/action.yml index 5f12609..1b2fc78 100644 --- a/action.yml +++ b/action.yml @@ -34,13 +34,13 @@ runs: using: "composite" steps: - name: Setup StackQL - uses: stackql/setup-stackql@v2.2.1 + uses: stackql/setup-stackql@v2.2.3 with: use_wrapper: true - name: Execute StackQL Command id: exec-query - uses: stackql/stackql-exec@v2.2.1 + uses: stackql/stackql-exec@v2.2.3 with: query: ${{ inputs.test_query }} query_file_path: ${{ inputs.test_query_file_path }}