Skip to content

Commit

Permalink
Merge pull request #3 from data-catering/fix-one-of-gen
Browse files Browse the repository at this point in the history
Add in generator type as oneOf to ensure oneOf is used for data gener…
  • Loading branch information
pflooky authored Dec 2, 2024
2 parents 1d6afcf + 76e8088 commit 5ab7400
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 108 deletions.
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 62 additions & 46 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "insta-integration",
"description": "insta-integration GitHub Action",
"version": "1.0.10",
"version": "1.0.11",
"author": "data-catering",
"private": false,
"bin": {
Expand Down
20 changes: 11 additions & 9 deletions schema/insta-integration-config-latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,17 @@
"relationship": {
"type": "object",
"description": "Define any relationships between data generation data sources. For example, 'account_number' field being the same across two Postgres tables accounts and balances.",
"additionalProperties": {
"type": "array",
"items": {
"type": "string",
"description": "Uses the pattern: '<name of generation>.<field name>'",
"pattern": "^[a-zA-Z0-9_-]+\\.[a-zA-Z0-9_-]+$"
"patternProperties": {
"^[a-zA-Z0-9_-]+\\.[a-zA-Z0-9_-]+$": {
"type": "array",
"items": {
"type": "string",
"description": "Uses the pattern: '<name of generation>.<field name>'",
"pattern": "^[a-zA-Z0-9_-]+\\.[a-zA-Z0-9_-]+$"
}
}
}
},
"additionalProperties": false
},
"validation": {
"type": "object",
Expand Down Expand Up @@ -627,8 +630,7 @@
"additionalProperties": false
}
},
"additionalProperties": false,
"required": ["command"]
"additionalProperties": false
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { program } = require('commander')
const { run } = require('./main')

program
.version('1.0.3')
.version('1.0.11')
.description(
'insta-integration CLI - Simple integration testing for any application or job'
)
Expand All @@ -21,7 +21,7 @@ program
.option(
'-d, --data-caterer-version <version>',
'Version of data-caterer Docker image',
'0.12.0'
'0.12.2'
)
.option(
'-i, --insta-infra-folder <folder>',
Expand Down
106 changes: 61 additions & 45 deletions src/insta-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ function extractDataGenerationTasks(
return Object.fromEntries(
Object.entries(f).map(fe => {
if (fe[0] === 'options') {
return ['generator', { options: fe[1] }]
if (Object.hasOwn(fe[1], 'oneOf')) {
return [
'generator',
{ type: 'oneOf', options: fe[1] }
]
} else {
return ['generator', { options: fe[1] }]
}
} else {
return fe
}
Expand Down Expand Up @@ -446,63 +453,72 @@ async function runApplication(
appIndex,
waitForFinish
) {
logger.info('Running application/job')
setEnvironmentVariables(runConf)
const logsFolder = `${baseFolder}/logs`
if (!fs.existsSync(logsFolder)) {
fs.mkdirSync(logsFolder)
}
try {
const logFile = `${logsFolder}/app_output_${appIndex}.log`
const logStream = fs.createWriteStream(logFile, { flags: 'w+' })
// Run in the background
const runApp = spawn(runConf.command, [], {
cwd: configFolder,
shell: true
})
runApp.stdout.pipe(logStream)
runApp.stderr.pipe(logStream)

if (waitForFinish) {
logger.info({
message: 'Waiting for command to finish',
command: runConf.command
if (runConf.command) {
logger.info('Running application/job')
setEnvironmentVariables(runConf)
const logsFolder = `${baseFolder}/logs`
if (!fs.existsSync(logsFolder)) {
fs.mkdirSync(logsFolder)
}
try {
const logFile = `${logsFolder}/app_output_${appIndex}.log`
const logStream = fs.createWriteStream(logFile, { flags: 'w+' })
// Run in the background
const runApp = spawn(runConf.command, [], {
cwd: configFolder,
shell: true
})
await new Promise(resolve => {
runApp.stdout.pipe(logStream)
runApp.stderr.pipe(logStream)

if (waitForFinish) {
logger.info({
message: 'Waiting for command to finish',
command: runConf.command
})
await new Promise(resolve => {
runApp.on('close', function (code) {
logger.info(`Application ${appIndex} exited with code ${code}`)
showLogFileContent(logFile)
resolve()
})
})
} else {
runApp.on('close', function (code) {
logger.info(`Application ${appIndex} exited with code ${code}`)
showLogFileContent(logFile)
resolve()
})
})
} else {
runApp.on('close', function (code) {
logger.info(`Application ${appIndex} exited with code ${code}`)
}

runApp.on('error', function (err) {
logger.error(`Application ${appIndex} failed with error`)
logger.error(err)
showLogFileContent(logFile)
throw new Error(err)
})
return { runApp, logStream }
} catch (error) {
logger.error(`Failed to run application/job, command=${runConf.command}`)
throw new Error(error)
}

runApp.on('error', function (err) {
logger.error(`Application ${appIndex} failed with error`)
logger.error(err)
showLogFileContent(logFile)
throw new Error(err)
})
return { runApp, logStream }
} catch (error) {
logger.error(`Failed to run application/job, command=${runConf.command}`)
throw new Error(error)
} else {
logger.debug('No command defined')
return null
}
}

function shutdownApplication(applicationProcess) {
logger.debug('Attempting to close log stream')
applicationProcess.logStream.close()
logger.debug(`Attempting to shut down application`)
if (applicationProcess && applicationProcess.runApp) {
applicationProcess.runApp.kill()
if (applicationProcess !== null) {
logger.debug('Attempting to close log stream')
applicationProcess.logStream.close()
logger.debug(`Attempting to shut down application`)
if (applicationProcess && applicationProcess.runApp) {
applicationProcess.runApp.kill()
} else {
logger.debug(`Application already stopped`)
}
} else {
logger.debug(`Application already stopped`)
logger.debug('Application process is null, not attempting to shutdown')
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function getBaseFolder(baseFolder) {
}

function getDataCatererVersion(dataCatererVersion) {
return !dataCatererVersion ? '0.12.1' : dataCatererVersion
return !dataCatererVersion ? '0.12.2' : dataCatererVersion
}

function getConfiguration() {
Expand Down

0 comments on commit 5ab7400

Please sign in to comment.