 sshkey_pub_path =  "../swops-secret/cotest-rsa.pub"
 sshkey_prv_path =  "../swops-secret/cotest-rsa"
 fs.chmodSync sshkey_prv_path, 0o600
+
+ssh_cmd = (cmd, callback) ->
+  ssh = "ssh #{boxname}@#{host} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o PreferredAuthentications=publickey -o LogLevel=ERROR -i #{sshkey_prv_path} '#{cmd}'"
+  exec ssh, (err, stdout, stderr) ->
+    callback err, stdout, stderr
 
 describe 'Integration testing', ->
   describe 'When I use the http API', ->

    it 'the CORS headers are present'
  describe 'When I login to my box', ->
    it 'SSH works', (done) ->
      cmd = "ssh #{boxname}@#{host} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o PreferredAuthentications=publickey -o LogLevel=ERROR -i #{sshkey_prv_path} 'exit 99'"
      exec cmd, (err, stdout_, stderr_) ->
          err.code.should.equal 99
          done()

    it 'I can see my README.md'
    it 'I can see my git repo'
    it 'I cannot see any other box'
  describe 'When I publish some files', ->
    before (done) ->
      cmd = "echo -n Testing > http/index.html"
      ssh = "ssh #{boxname}@#{host} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o PreferredAuthentications=publickey -o LogLevel=ERROR -i #{sshkey_prv_path} '#{cmd}'"
      exec ssh, (err, stdout_, stderr_) ->
          done()

    it 'I can see a root index page', (done) ->
      response = request.get "#{baseurl}/#{boxname}/http/", (err, resp, body) ->

  describe 'When I use the SQL web API', ->
    resp = null
    before (done) ->
       ssh_cmd '''echo "create table swdata (num int); insert into swdata values (7);" |
          sqlite3 scraperwiki.sqlite''', ->
         options =
           uri: "http://#{host}/#{boxname}/sqlite"
           qs:
             q: "select num*num from swdata"
         request.get options, (err, response, body) ->
           should.not.exist err
           resp = response
           done()

    it 'has status 200', ->
      resp.should.have.status 200
