Skip to content

Commit

Permalink
DSBD-31: unit test update to address the removal of a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3op2 committed Aug 3, 2022
1 parent 6abd0c6 commit 2f9d605
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions src/controllers/scenario/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ describe('/scenario/{example} endpoint', () => {
let stubs = {}

beforeEach(async () => {
stubs.exec = stub(child, 'exec').yields(null, { stdout: 'ok' })
stubs.exec = stub(child, 'exec')
stubs.exec.onCall(0).yields(null, 'stdout - some output')
stubs.exec.onCall(1)
stubs.exec.onCall(2).yields(null, 'stdout - some output')
stubs.exec.onCall(3)
res = await execute()
})

Expand All @@ -28,7 +32,11 @@ describe('/scenario/{example} endpoint', () => {
describe('if executing binaries fails', () => {
beforeEach(async () => {
stubs.exec.restore()
stubs.exec = stub(child, 'exec').yields({ msg: 'fatal error' }, 'stdout - some output')
stubs.exec = stub(child, 'exec')
stubs.exec.onCall(0).yields({ message: 'cheri - error' }, 'stdout - some output')
stubs.exec.onCall(1)
stubs.exec.onCall(2).yields({ message: 'aarch64 - error' }, 'stdout - some output')
stubs.exec.onCall(3)
res = await execute()
})

Expand All @@ -37,12 +45,12 @@ describe('/scenario/{example} endpoint', () => {
expect(res.aarch64).to.deep.equal({
status: 'error',
output: 'stdout - some output',
exception: { msg: 'fatal error' },
exception: { message: 'aarch64 - error' },
})
expect(res.cheri).to.deep.equal({
status: 'error',
output: 'stdout - some output',
exception: { msg: 'fatal error' },
exception: { message: 'cheri - error' },
})
})
})
Expand All @@ -52,7 +60,9 @@ describe('/scenario/{example} endpoint', () => {
stubs.exec.restore()
stubs.exec = stub(child, 'exec')
stubs.exec.onCall(0).yields({ msg: 'fatal error' }, 'stdout - some output')
stubs.exec.onCall(1).yields(null, 'it was a success')
stubs.exec.onCall(1)
stubs.exec.onCall(2).yields(null, 'it was a success')
stubs.exec.onCall(3)
res = await execute()
})

Expand All @@ -77,15 +87,11 @@ describe('/scenario/{example} endpoint', () => {
expect(res).to.deep.equal({
aarch64: {
status: 'success',
output: {
stdout: 'ok',
},
output: 'stdout - some output',
},
cheri: {
status: 'success',
output: {
stdout: 'ok',
},
output: 'stdout - some output',
},
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/scenario/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class scenario extends Controller implements IScenario {

return new Promise((resolve) => {
exec(`${scp}; ${ssh}`, (err, stdout) => {
exec(rm)
exec(rm) // fire and forget, remove binary file
return resolve({
status: err ? 'error': 'success',
output: stdout,
Expand Down

0 comments on commit 2f9d605

Please sign in to comment.