From 092ca5a46e4af8a756e18d6e602db69bad670910 Mon Sep 17 00:00:00 2001 From: Sander Blue Date: Thu, 23 May 2024 13:57:35 -0500 Subject: [PATCH] chore: testing drift detection script --- .github/workflows/test_unit.yml | 71 +++++++++++++++++++-------------- scripts/detect-state-drift.js | 54 +++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 29 deletions(-) create mode 100755 scripts/detect-state-drift.js diff --git a/.github/workflows/test_unit.yml b/.github/workflows/test_unit.yml index 60ad540fb..60cebe634 100644 --- a/.github/workflows/test_unit.yml +++ b/.github/workflows/test_unit.yml @@ -35,60 +35,73 @@ jobs: run: | make test-unit cover-report - - name: Create test failure report - id: test-failure-report - if: ${{ failure() }} - run: | - go install github.com/mfridman/tparse@latest - make test-failure-report - tparse -file=coverage/unit.failures -format=markdown > coverage/unit.md - - - name: Prepare multiline test report - id: payload - shell: bash - if: ${{ always() }} - run: | - cat coverage/unit.md - result=$(cat coverage/unit.md) - - echo "Result: $result" - - echo 'UNIT_TEST_FAILURES< { + const fs = require('fs'); + + // Read the text from the file + fs.readFile('coverage/unit.report', 'utf8', (err, data) => { + if (err) { + console.error('Error reading file:', err); + return; + } + + // Split the text into individual lines + const lines = data.trim().split('\n'); + + // Parse each line and convert it to JSON + const jsonData = lines.map(line => { + try { + return JSON.parse(line); + } catch (error) { + console.error('Error parsing line:', error); + return null; + } + }); + + // Print the resulting JSON array + // console.log(jsonData); + + const report = jsonData.filter(data => { + return data.Output ? data.Output.includes('error: After applying this test step, the plan was not empty') : false; + }).map(t => t.Output.trim()); + + console.log(report); + + let msg = 'error: After applying this test step, the plan was not empty'; + if (report.length > 0) { + msg = `'${report.join('\n')}'`; + } + + core.setOutput('failed_tests_with_drift', msg); + + // // Convert JSON data to string + // const jsonString = JSON.stringify(failedTests, null, 2); + + // // Write the JSON data to a file + // fs.writeFile('output.json', jsonString, 'utf8', err => { + // if (err) { + // console.error('Error writing file:', err); + // return; + // } + // console.log('JSON data has been written to output.json'); + // }); + }); +};