11import { expect } from 'chai'
22import { download } from '../src/tasks/submission'
33import * 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
510describe ( '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