Skip to content

Commit

Permalink
Merge pull request #13 from digicatapult/feature/dsbd-52
Browse files Browse the repository at this point in the history
Feature/dsbd 52
  • Loading branch information
n3op2 authored Aug 23, 2022
2 parents 82dc312 + a7f5e6d commit 7af1f1f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 67 deletions.
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,6 +1,6 @@
{
"name": "@digicatapult/morello-api",
"version": "0.4.0",
"version": "0.4.1",
"description": "An interface for executing binaries on it's self and morello host.",
"main": "src/index.ts",
"scripts": {
Expand Down
61 changes: 9 additions & 52 deletions src/controllers/scenario/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ describe('/scenario/{example} endpoint', () => {

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

Expand All @@ -33,66 +31,25 @@ describe('/scenario/{example} endpoint', () => {
beforeEach(async () => {
stubs.exec.restore()
stubs.exec = stub(child, 'exec')
stubs.exec.onCall(0).yields({ message: 'cheri - error' }, 'stdout - some output')
stubs.exec.onCall(0).yields({ message: 'error' }, 'stdout - some error output')
stubs.exec.onCall(1)
stubs.exec.onCall(2).yields({ message: 'aarch64 - error' }, 'stdout - some output')
stubs.exec.onCall(3)
res = await execute()
})

it('returns correct state along with exceptions if both binaries fail', () => {
expect(res).to.include.all.keys(['aarch64', 'cheri'])
expect(res.aarch64).to.deep.equal({
status: 'error',
output: 'stdout - some output',
exception: { message: 'aarch64 - error' },
})
expect(res.cheri).to.deep.equal({
status: 'error',
output: 'stdout - some output',
exception: { message: 'cheri - error' },
})
})
})

describe('and if some binaries fail and some succeed', () => {
beforeEach(async () => {
stubs.exec.restore()
stubs.exec = stub(child, 'exec')
stubs.exec.onCall(0).yields({ msg: 'fatal error' }, 'stdout - some output')
stubs.exec.onCall(1)
stubs.exec.onCall(2).yields(null, 'it was a success')
stubs.exec.onCall(3)
res = await execute()
})

it('returns formatted output with one with clear indication of failed ones', () => {
expect(res).to.include.all.keys(['aarch64', 'cheri'])
expect(res).to.deep.equal({
aarch64: {
status: 'success',
output: 'it was a success',
},
cheri: {
status: 'error',
output: 'stdout - some output',
exception: { msg: 'fatal error' },
},
status: 'error',
output: 'stdout - some error output',
exception: { message: 'error' },
})
})
})

it('returns a formatted output of both architectuures', () => {
expect(res).to.include.all.keys(['aarch64', 'cheri'])
it('returns a formatted output', () => {
expect(res).to.include.all.keys(['output', 'status'])
expect(res).to.deep.equal({
aarch64: {
status: 'success',
output: 'stdout - some output',
},
cheri: {
status: 'success',
output: 'stdout - some output',
},
status: 'success',
output: 'stdout - success',
})
})
})
9 changes: 3 additions & 6 deletions src/controllers/scenario/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'tsoa'
import config from 'config'
import { exec } from 'child_process'
import { ExamplesResult, IScenario, HostResponse, Executables } from '../../../types'
import { IScenario, HostResponse, Executables } from '../../../types'
import Logger from '../../utils/Logger'

@Route('scenario')
Expand Down Expand Up @@ -42,12 +42,9 @@ export class scenario extends Controller implements IScenario {
}

@Get('{executable}')
public async get(@Path() executable: Executables , @Query() params: string[]): Promise<ExamplesResult> {
public async get(@Path() executable: Executables , @Query() params: string[]): Promise<HostResponse> {
this.log.debug(`attempting to execute ${executable} scenario with [${params}] arguments`)

return ({
cheri: await this.execute(`${executable}-cheri ${params}`),
aarch64: await this.execute(`${executable}-aarch64 ${params}`),
})
return this.execute(`${executable} ${params}`)
}
}
7 changes: 1 addition & 6 deletions types/models/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export interface IScenario {
readonly address: string
readonly port: number
log: typeof Logger
get: (executable: Executables, params: string[]) => Promise<ExamplesResult>
get: (executable: Executables, params: string[]) => Promise<HostResponse>
execute: (cmd: string) => Promise<HostResponse>
}

export interface ExamplesResult {
aarch64: HostResponse,
cheri: HostResponse,
}

0 comments on commit 7af1f1f

Please sign in to comment.