Merge branch 'per-user-containers-part-2'
Conflicts: app/coffee/CompileController.coffee
This commit is contained in:
@@ -146,12 +146,12 @@ describe "CompileController", ->
|
||||
column: @column.toString()
|
||||
@res.send = sinon.stub()
|
||||
|
||||
@CompileManager.syncFromCode = sinon.stub().callsArgWith(4, null, @pdfPositions = ["mock-positions"])
|
||||
@CompileManager.syncFromCode = sinon.stub().callsArgWith(5, null, @pdfPositions = ["mock-positions"])
|
||||
@CompileController.syncFromCode @req, @res, @next
|
||||
|
||||
it "should find the corresponding location in the PDF", ->
|
||||
@CompileManager.syncFromCode
|
||||
.calledWith(@project_id, @file, @line, @column)
|
||||
.calledWith(@project_id, undefined, @file, @line, @column)
|
||||
.should.equal true
|
||||
|
||||
it "should return the positions", ->
|
||||
@@ -175,12 +175,12 @@ describe "CompileController", ->
|
||||
v: @v.toString()
|
||||
@res.send = sinon.stub()
|
||||
|
||||
@CompileManager.syncFromPdf = sinon.stub().callsArgWith(4, null, @codePositions = ["mock-positions"])
|
||||
@CompileManager.syncFromPdf = sinon.stub().callsArgWith(5, null, @codePositions = ["mock-positions"])
|
||||
@CompileController.syncFromPdf @req, @res, @next
|
||||
|
||||
it "should find the corresponding location in the code", ->
|
||||
@CompileManager.syncFromPdf
|
||||
.calledWith(@project_id, @page, @h, @v)
|
||||
.calledWith(@project_id, undefined, @page, @h, @v)
|
||||
.should.equal true
|
||||
|
||||
it "should return the positions", ->
|
||||
@@ -201,12 +201,12 @@ describe "CompileController", ->
|
||||
image: @image = "example.com/image"
|
||||
@res.send = sinon.stub()
|
||||
|
||||
@CompileManager.wordcount = sinon.stub().callsArgWith(3, null, @texcount = ["mock-texcount"])
|
||||
@CompileManager.wordcount = sinon.stub().callsArgWith(4, null, @texcount = ["mock-texcount"])
|
||||
@CompileController.wordcount @req, @res, @next
|
||||
|
||||
it "should return the word count of a file", ->
|
||||
@CompileManager.wordcount
|
||||
.calledWith(@project_id, @file, @image)
|
||||
.calledWith(@project_id, undefined, @file, @image)
|
||||
.should.equal true
|
||||
|
||||
it "should return the texcount info", ->
|
||||
|
||||
@@ -43,11 +43,12 @@ describe "CompileManager", ->
|
||||
resources: @resources = "mock-resources"
|
||||
rootResourcePath: @rootResourcePath = "main.tex"
|
||||
project_id: @project_id = "project-id-123"
|
||||
user_id: @user_id = "1234"
|
||||
compiler: @compiler = "pdflatex"
|
||||
timeout: @timeout = 42000
|
||||
imageName: @image = "example.com/image"
|
||||
@Settings.compileDir = "compiles"
|
||||
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}"
|
||||
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
|
||||
@ResourceWriter.syncResourcesToDisk = sinon.stub().callsArg(3)
|
||||
@LatexRunner.runLatex = sinon.stub().callsArg(2)
|
||||
@OutputFileFinder.findOutputFiles = sinon.stub().callsArgWith(2, null, @output_files)
|
||||
@@ -65,7 +66,7 @@ describe "CompileManager", ->
|
||||
|
||||
it "should run LaTeX", ->
|
||||
@LatexRunner.runLatex
|
||||
.calledWith(@project_id, {
|
||||
.calledWith("#{@project_id}-#{@user_id}", {
|
||||
directory: @compileDir
|
||||
mainFile: @rootResourcePath
|
||||
compiler: @compiler
|
||||
@@ -104,12 +105,12 @@ describe "CompileManager", ->
|
||||
@proc.stdout = new EventEmitter()
|
||||
@proc.stderr = new EventEmitter()
|
||||
@child_process.spawn = sinon.stub().returns(@proc)
|
||||
@CompileManager.clearProject @project_id, @callback
|
||||
@CompileManager.clearProject @project_id, @user_id, @callback
|
||||
@proc.emit "close", 0
|
||||
|
||||
it "should remove the project directory", ->
|
||||
@child_process.spawn
|
||||
.calledWith("rm", ["-r", "#{@Settings.path.compilesDir}/#{@project_id}"])
|
||||
.calledWith("rm", ["-r", "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"])
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
@@ -123,13 +124,13 @@ describe "CompileManager", ->
|
||||
@proc.stdout = new EventEmitter()
|
||||
@proc.stderr = new EventEmitter()
|
||||
@child_process.spawn = sinon.stub().returns(@proc)
|
||||
@CompileManager.clearProject @project_id, @callback
|
||||
@CompileManager.clearProject @project_id, @user_id, @callback
|
||||
@proc.stderr.emit "data", @error = "oops"
|
||||
@proc.emit "close", 1
|
||||
|
||||
it "should remove the project directory", ->
|
||||
@child_process.spawn
|
||||
.calledWith("rm", ["-r", "#{@Settings.path.compilesDir}/#{@project_id}"])
|
||||
.calledWith("rm", ["-r", "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"])
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with an error from the stderr", ->
|
||||
@@ -137,7 +138,7 @@ describe "CompileManager", ->
|
||||
.calledWith(new Error())
|
||||
.should.equal true
|
||||
|
||||
@callback.args[0][0].message.should.equal "rm -r #{@Settings.path.compilesDir}/#{@project_id} failed: #{@error}"
|
||||
@callback.args[0][0].message.should.equal "rm -r #{@Settings.path.compilesDir}/#{@project_id}-#{@user_id} failed: #{@error}"
|
||||
|
||||
describe "syncing", ->
|
||||
beforeEach ->
|
||||
@@ -150,17 +151,17 @@ describe "CompileManager", ->
|
||||
@column = 3
|
||||
@file_name = "main.tex"
|
||||
@child_process.execFile = sinon.stub()
|
||||
@Settings.path.synctexBaseDir = (project_id) => "#{@Settings.path.compilesDir}/#{@project_id}"
|
||||
@Settings.path.synctexBaseDir = (project_id) => "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
|
||||
|
||||
describe "syncFromCode", ->
|
||||
beforeEach ->
|
||||
@child_process.execFile.callsArgWith(3, null, @stdout = "NODE\t#{@page}\t#{@h}\t#{@v}\t#{@width}\t#{@height}\n", "")
|
||||
@CompileManager.syncFromCode @project_id, @file_name, @line, @column, @callback
|
||||
@CompileManager.syncFromCode @project_id, @user_id, @file_name, @line, @column, @callback
|
||||
|
||||
it "should execute the synctex binary", ->
|
||||
bin_path = Path.resolve(__dirname + "/../../../bin/synctex")
|
||||
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}/output.pdf"
|
||||
file_path = "#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}"
|
||||
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/output.pdf"
|
||||
file_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/#{@file_name}"
|
||||
@child_process.execFile
|
||||
.calledWith(bin_path, ["code", synctex_path, file_path, @line, @column], timeout: 10000)
|
||||
.should.equal true
|
||||
@@ -178,12 +179,12 @@ describe "CompileManager", ->
|
||||
|
||||
describe "syncFromPdf", ->
|
||||
beforeEach ->
|
||||
@child_process.execFile.callsArgWith(3, null, @stdout = "NODE\t#{@Settings.path.compilesDir}/#{@project_id}/#{@file_name}\t#{@line}\t#{@column}\n", "")
|
||||
@CompileManager.syncFromPdf @project_id, @page, @h, @v, @callback
|
||||
@child_process.execFile.callsArgWith(3, null, @stdout = "NODE\t#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/#{@file_name}\t#{@line}\t#{@column}\n", "")
|
||||
@CompileManager.syncFromPdf @project_id, @user_id, @page, @h, @v, @callback
|
||||
|
||||
it "should execute the synctex binary", ->
|
||||
bin_path = Path.resolve(__dirname + "/../../../bin/synctex")
|
||||
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}/output.pdf"
|
||||
synctex_path = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}/output.pdf"
|
||||
@child_process.execFile
|
||||
.calledWith(bin_path, ["pdf", synctex_path, @page, @h, @v], timeout: 10000)
|
||||
.should.equal true
|
||||
@@ -209,15 +210,15 @@ describe "CompileManager", ->
|
||||
@Settings.path.compilesDir = "/local/compile/directory"
|
||||
@image = "example.com/image"
|
||||
|
||||
@CompileManager.wordcount @project_id, @file_name, @image, @callback
|
||||
@CompileManager.wordcount @project_id, @user_id, @file_name, @image, @callback
|
||||
|
||||
it "should run the texcount command", ->
|
||||
@directory = "#{@Settings.path.compilesDir}/#{@project_id}"
|
||||
@directory = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
|
||||
@file_path = "$COMPILE_DIR/#{@file_name}"
|
||||
@command =[ "texcount", "-inc", @file_path, "-out=" + @file_path + ".wc"]
|
||||
|
||||
@CommandRunner.run
|
||||
.calledWith(@project_id, @command, @directory, @image, @timeout)
|
||||
.calledWith("#{@project_id}-#{@user_id}", @command, @directory, @image, @timeout)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with the parsed output", ->
|
||||
|
||||
@@ -13,6 +13,7 @@ describe "ProjectPersistenceManager", ->
|
||||
"./db": @db = {}
|
||||
@callback = sinon.stub()
|
||||
@project_id = "project-id-123"
|
||||
@user_id = "1234"
|
||||
|
||||
describe "clearExpiredProjects", ->
|
||||
beforeEach ->
|
||||
@@ -21,12 +22,13 @@ describe "ProjectPersistenceManager", ->
|
||||
"project-id-2"
|
||||
]
|
||||
@ProjectPersistenceManager._findExpiredProjectIds = sinon.stub().callsArgWith(0, null, @project_ids)
|
||||
@ProjectPersistenceManager.clearProject = sinon.stub().callsArg(1)
|
||||
@ProjectPersistenceManager.clearProjectFromCache = sinon.stub().callsArg(1)
|
||||
@CompileManager.clearExpiredProjects = sinon.stub().callsArg(1)
|
||||
@ProjectPersistenceManager.clearExpiredProjects @callback
|
||||
|
||||
it "should clear each expired project", ->
|
||||
for project_id in @project_ids
|
||||
@ProjectPersistenceManager.clearProject
|
||||
@ProjectPersistenceManager.clearProjectFromCache
|
||||
.calledWith(project_id)
|
||||
.should.equal true
|
||||
|
||||
@@ -37,8 +39,8 @@ describe "ProjectPersistenceManager", ->
|
||||
beforeEach ->
|
||||
@ProjectPersistenceManager._clearProjectFromDatabase = sinon.stub().callsArg(1)
|
||||
@UrlCache.clearProject = sinon.stub().callsArg(1)
|
||||
@CompileManager.clearProject = sinon.stub().callsArg(1)
|
||||
@ProjectPersistenceManager.clearProject @project_id, @callback
|
||||
@CompileManager.clearProject = sinon.stub().callsArg(2)
|
||||
@ProjectPersistenceManager.clearProject @project_id, @user_id, @callback
|
||||
|
||||
it "should clear the project from the database", ->
|
||||
@ProjectPersistenceManager._clearProjectFromDatabase
|
||||
@@ -52,7 +54,7 @@ describe "ProjectPersistenceManager", ->
|
||||
|
||||
it "should clear the project compile folder", ->
|
||||
@CompileManager.clearProject
|
||||
.calledWith(@project_id)
|
||||
.calledWith(@project_id, @user_id)
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
|
||||
Reference in New Issue
Block a user