   afterEach (done) ->
     return process.nextTick done if cleanup.length is 0
 
-    client.s3.deleteObjects Delete: Objects: cleanup, (err) ->
+    upload.s3.deleteObjects Delete: Objects: cleanup, (err) ->
       throw err if err
       cleanup = []
       done()

      , /Bucket name can not be undefined/

    it 'should set default values if not provided', ->
      client = new Upload 'myBucket'

      assert client.s3 instanceof require('aws-sdk').S3
      assert client.versions instanceof Array
      assert.equal client.awsBucketPath, ''
      assert.equal client.awsBucketUrl, undefined
      assert.equal client.awsBucketAcl, 'privat'
      assert.equal client.resizeQuality, 70
      assert.equal client.keepOriginal, true
      assert.equal client.returnExif, false
      assert.equal client.tmpDir, '/tmp/'
      assert.equal client.tmpPrefix, 'gm-'

    it 'should override default values'

  describe '#_getRandomPath()', ->
    it 'should return a new random path', ->
      path = client._getRandomPath()
      assert(/^images_test\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}$/.test(path))

  describe '#_uploadPathIsAvailable()', ->
    it 'should return true for avaiable path', (done) ->
      client.s3.listObjects = (opts, cb) -> process.nextTick -> cb null, Contents: []
      client._uploadPathIsAvailable 'some/path/', (err, path, isAvaiable) ->
        assert.ifError err
        assert.equal isAvaiable, true
        done()

    it 'should return false for unavaiable path', (done) ->
      client.s3.listObjects = (opts, cb) -> process.nextTick -> cb null, Contents: [opts.Prefix]
      client._uploadPathIsAvailable 'some/path/', (err, path, isAvaiable) ->
        assert.ifError err
        assert.equal isAvaiable, false
        done()

  describe '#_uploadGeneratePath()', ->
    it 'should return an error if path is taken', (done) ->
      client._uploadPathIsAvailable = (path, cb) -> process.nextTick -> cb null, path, false
      client._uploadGeneratePath (err, path) ->
        assert /Path '[^']+' not avaiable!/.test err
        done()

    it 'should return an avaiable path', (done) ->
      client._uploadPathIsAvailable = (path, cb) -> process.nextTick -> cb null, path, true
      client._uploadGeneratePath (err, path) ->
        assert.ifError err
        assert /^images_test\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}\/[A-Za-z0-9]{2}$/.test(path)
        done()

hash = require('crypto').createHash
rand = require('crypto').pseudoRandomBytes

upload = listObjects = putObject = null
cleanup = []

beforeEach ->
  upload = new Upload 'turadmin',
    awsBucketPath: 'images_test/'
    awsBucketUrl: 'https://s3-eu-west-1.amazonaws.com/turadmin/'
    awsBucketAcl: 'public-read'
