Skip to content

Commit 259ee58

Browse files
committed
submission scenario setup done with UT
Signed-off-by: Tathagat Thapliyal <tathagat.thapliyal@gmail.com>
1 parent 097879c commit 259ee58

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/tasks/submission.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SubmissionScenario implements Scenario {
3333
return Promise.all(job.testcases.map(async testcase => {
3434
const rootDir = path.join(testCasesDir, '' + testcase.id)
3535
mkdir('-p', rootDir)
36+
console.log(rootDir)
3637
const input = await download(testcase.input, path.join(rootDir, 'stdin'))
3738
const output = await download(testcase.output, path.join(rootDir, 'stdout'))
3839
}))

test/submissionScenario.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { expect } from 'chai'
22
import { download } from '../src/tasks/submission'
33
import * as fs from 'fs'
4+
import { mkdir, rm } from 'shelljs'
5+
import config = require('../config.js')
6+
import * as path from 'path'
7+
import SubmissionScenario from '../src/tasks/submission'
8+
import { SubmissionJob } from '../src/types/job'
49

510
describe('Submission Scenario', () => {
611
it('should download', async () => {
@@ -11,4 +16,33 @@ describe('Submission Scenario', () => {
1116
const content = fs.readFileSync('/tmp/input').toString()
1217
expect(content.trim()).to.eq('World')
1318
})
19+
})
20+
21+
describe('Submission Scenario Dir structure', () => {
22+
it('should setup', async () => {
23+
const source = 'print("Hello World")'
24+
25+
const job: SubmissionJob = {
26+
id: 1,
27+
source: (new Buffer(source)).toString('base64'),
28+
lang: 'py3',
29+
timelimit: 5,
30+
testcases: [{ id: 122, input: 'https://minio.cb.lk/public/input', output: 'https://minio.cb.lk/public/output' }]
31+
}
32+
33+
rm('-rf', config.RUNBOX.DIR)
34+
mkdir('-p', config.RUNBOX.DIR)
35+
const currentJobDir = path.join(config.RUNBOX.DIR, job.id.toString())
36+
mkdir('-p', currentJobDir)
37+
38+
await SubmissionScenario.setup(currentJobDir, job)
39+
40+
//assertions
41+
const stdin = fs.readFileSync(path.join(currentJobDir, 'testcases', '' + job.testcases[0].id, 'stdin')).toString()
42+
expect(stdin.trim()).to.eq('World')
43+
44+
const stdout = fs.readFileSync(path.join(currentJobDir, 'testcases', '' + job.testcases[0].id, 'stdout')).toString()
45+
expect(stdout.trim()).to.eq('Hello World')
46+
47+
})
1448
})

0 commit comments

Comments
 (0)