Skip to content

Commit

Permalink
[CI] Add a test-result folder in backend and upload to JFrog to help …
Browse files Browse the repository at this point in the history
…debug stream count issues.
  • Loading branch information
aHenryJard authored Jan 3, 2025
1 parent b5f6b59 commit 8a66e8b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ steps:
# Archive and upload each artefact that we need
- tar -czvf frontend-test-results-$DRONE_BUILD_NUMBER.tar.gz opencti-platform/opencti-front/test-results
- jf rt u frontend-test-results-$DRONE_BUILD_NUMBER.tar.gz $JFROG_REPOSITORY --build-name=$JFROG_BUILD_NAME --build-number=$DRONE_BUILD_NUMBER --url=$JFROG_URL --access-token=$JFROG_TOKEN
- tar -czvf backend-test-results-$DRONE_BUILD_NUMBER.tar.gz opencti-platform/opencti-graphql/test-results
- jf rt u backend-test-results-$DRONE_BUILD_NUMBER.tar.gz $JFROG_REPOSITORY --build-name=$JFROG_BUILD_NAME --build-number=$DRONE_BUILD_NUMBER --url=$JFROG_URL --access-token=$JFROG_TOKEN
# Next line should be done only once at the end: it's recording and gathering build info
- jf rt bp $JFROG_BUILD_NAME $DRONE_BUILD_NUMBER --url=$JFROG_URL --access-token=$JFROG_TOKEN --build-url=$DRONE_BUILD_LINK
# Cleaning up old build in JFrog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FIVE_MINUTES, RAW_EVENTS_SIZE } from '../../utils/testQuery';
import { checkStreamData, checkStreamGenericContent, fetchStreamEvents, } from '../../utils/testStream';
import { PORT } from '../../../src/config/conf';
import { EVENT_TYPE_CREATE, EVENT_TYPE_DELETE, EVENT_TYPE_MERGE, EVENT_TYPE_UPDATE } from '../../../src/database/utils';
import { writeTestDataToFile } from '../../utils/testOutput';

describe('Raw streams tests', () => {
// We need to check the event format to be sure that everything is setup correctly
Expand All @@ -13,6 +14,7 @@ describe('Raw streams tests', () => {
async () => {
// Read all events from the beginning.
const events = await fetchStreamEvents(`http://localhost:${PORT}/stream`, { from: '0' });
writeTestDataToFile(JSON.stringify(events), 'raw-test-all-event.json');
// Check the number of events
// 01 - CHECK CREATE EVENTS.
const createEvents = events.filter((e) => e.type === EVENT_TYPE_CREATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { convertStoreToStix, convertTypeToStixType } from '../../../src/database
import { utcDate } from '../../../src/utils/format';
import { PORT } from '../../../src/config/conf';
import { READ_DATA_INDICES } from '../../../src/database/utils';
import { writeTestDataToFile } from '../../utils/testOutput';

describe('Live streams tests', () => {
const getElementsCounting = async () => {
Expand Down Expand Up @@ -49,6 +50,7 @@ describe('Live streams tests', () => {
const stixReport = convertStoreToStix(report);
const now = utcDate().toISOString();
const events = await fetchStreamEvents(`http://localhost:${PORT}/stream/live?from=0&recover=${now}`);
writeTestDataToFile(JSON.stringify(events), 'live-test-all-event.json');
expect(events.length).toBe(SYNC_LIVE_EVENTS_SIZE);
await checkResultCounting(events);
for (let index = 0; index < events.length; index += 1) {
Expand Down
17 changes: 17 additions & 0 deletions opencti-platform/opencti-graphql/tests/utils/testOutput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import fs from 'node:fs';
import { join } from 'node:path';

const TEST_OUTPUT_FOLDER = 'test-results';

/**
* Write content to a folder that will be archived at the end of test in CI.
* @param fileContent
* @param filename
*/
export const writeTestDataToFile = (fileContent: string, filename: string) => {
if (!fs.existsSync(TEST_OUTPUT_FOLDER)) {
fs.mkdirSync(TEST_OUTPUT_FOLDER, { recursive: true });
}
const filePath = join(TEST_OUTPUT_FOLDER, filename);
fs.writeFileSync(filePath, fileContent, {});
};

0 comments on commit 8a66e8b

Please sign in to comment.