Example #1
0
  'without callback': function (done) {
    var location = common.nextLocation()
    var db = levelup(location, { createIfMissing: true, errorIfExists: true })

    this.closeableDatabases.push(db)
    this.cleanupDirs.push(location)
    assert.isObject(db)
    assert.isTrue(db.options.createIfMissing)
    assert.isTrue(db.options.errorIfExists)
    assert.equals(db.location, location)

    db.on('ready', function () {
      assert.isTrue(db.isOpen())
      done()
    })
  },
 levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
   refute(err) // sanity
   this.closeableDatabases.push(db)
   assert.isTrue(db.isOpen())
   this.db = db
   done()
 }.bind(this))
Example #3
0
    levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
      refute(err, 'no error')
      assert.isTrue(db.isOpen())
      this.closeableDatabases.push(db)
      this.cleanupDirs.push(location)
      db.close(function (err) {
        refute(err)

        assert.isFalse(db.isOpen())

        levelup(location, function (err, db) { // no options object
          refute(err)
          assert.isObject(db)
          assert.isTrue(db.options.createIfMissing)
          assert.isFalse(db.options.errorIfExists)
          assert.equals(db.options.keyEncoding, 'utf8')
          assert.equals(db.options.valueEncoding, 'utf8')
          assert.equals(db.location, location)

            // read-only properties
          db.location = 'foo'
          assert.equals(db.location, location)

          done()
        })
      })
    }.bind(this))
 levelup(memdown(), function (err, db) {
   refute(err) // sanity
   this.closeableDatabases.push(db)
   assert.isTrue(db.isOpen())
   this.db = db
   done()
 }.bind(this))
Example #5
0
 this.openTestDatabase(function (db) {
   var ws = db.createWriteStream()
   ws.on('error', function (err) {
     refute(err)
   })
   assert.isTrue(ws.writable)
   assert.isFalse(ws.readable)
   ws.on('close', verify.bind(this, ws, db))
   this.sourceData.forEach(function (d) {
     ws.write(d)
     assert.isTrue(ws.writable)
     assert.isFalse(ws.readable)
   })
   assert.isTrue(ws.writable)
   assert.isFalse(ws.readable)
   ws.once('ready', ws.destroy)
 }.bind(this))
Example #6
0
      { createIfMissing: true, errorIfExists: true, keyEncoding: 'ascii', valueEncoding: 'json' }, function (err, db) {
        refute(err)

        this.closeableDatabases.push(db)
        this.cleanupDirs.push(location)
        assert.isObject(db)
        assert.isTrue(db.options.createIfMissing)
        assert.isTrue(db.options.errorIfExists)
        assert.equals(db.options.keyEncoding, 'ascii')
        assert.equals(db.options.valueEncoding, 'json')
        assert.equals(db.location, location)

        // read-only properties
        db.location = 'bar'
        assert.equals(db.location, location)

        done()
      }.bind(this)
Example #7
0
 levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
   this.closeableDatabases.push(db)
   refute(err)
   assert.isTrue(db.isOpen())
   fs.stat(this.cleanupDirs[0], function (err, stat) {
     refute(err)
     assert(stat.isDirectory())
     done()
   })
 }.bind(this))
        db.batch(this.sourceData.slice(), function (err) {
          refute(err)

          var rs = db.valueStream()
          assert.isFalse(rs.writable)
          assert.isTrue(rs.readable)
          rs.on('ready', this.readySpy)
          rs.on('data', this.dataSpy)
          rs.on('end', this.endSpy)
          rs.on('close', this.verify.bind(this, rs, this.sourceValues, done))
        }.bind(this))
Example #9
0
        levelup(location, function (err, db) { // no options object
          refute(err)
          assert.isObject(db)
          assert.isTrue(db.options.createIfMissing)
          assert.isFalse(db.options.errorIfExists)
          assert.equals(db.options.keyEncoding, 'utf8')
          assert.equals(db.options.valueEncoding, 'utf8')
          assert.equals(db.location, location)

            // read-only properties
          db.location = 'foo'
          assert.equals(db.location, location)

          done()
        })
Example #10
0
    levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
      refute(err) // sanity
      this.closeableDatabases.push(db)
      assert.isTrue(db.isOpen())

      db.close(function () {
        assert.isFalse(db.isOpen())

        levelup(this.cleanupDirs[0], { errorIfExists: false }, function (err, db) {
          refute(err)
          this.closeableDatabases.push(db)
          assert.isTrue(db.isOpen())
          done()
        }.bind(this))
      }.bind(this))
    }.bind(this))
Example #11
0
        db.batch(this.sourceData.slice(), function (err) {
          refute(err)

          // 2) Create an iterator on the current data, pipe it through a SlowStream
          //    to make *sure* that we're going to be reading it for longer than it
          //    takes to overwrite the data in there.

          var rs = db.readStream()
          assert.isFalse(rs.writable)
          assert.isTrue(rs.readable)
          rs = rs.pipe(new SlowStream({ maxWriteInterval: 5 }))
          rs.on('data' , this.dataSpy)
          rs.once('end'  , this.endSpy)
          rs.on('end', function () {
            rs.readable = false
            rs.writable = false
          })

          rs.once('close', delayed.delayed(this.verify.bind(this, rs, done), 0.05))

          process.nextTick(function () {
            // 3) Concoct and write new random data over the top of existing items.
            //    If we're not using a snapshot then then we'd expect the test
            //    to fail because it'll pick up these new values rather than the
            //    old ones.
            var newData = []
              , i
              , k

            for (i = 0; i < 100; i++) {
              k = (i < 10 ? '0' : '') + i
              newData.push({
                  type  : 'put'
                , key   : k
                , value : Math.random()
              })
            }
            // using sync:true here to ensure it's written fully to disk
            db.batch(newData.slice(), { sync: true }, function (err) {
              refute(err)
              // we'll return here faster than it takes the readStream to complete
            })
          }.bind(this))
        }.bind(this))
Example #12
0
        it("returns true for an array of nested matchers", function () {
            var match = sinonMatch([sinonMatch({ str: "sinon" })]);

            assert.isTrue(match.test([{ str: "sinon", foo: "bar" }]));
        });
Example #13
0
 this.sourceData.forEach(function (d) {
   ws.write(d)
   assert.isTrue(ws.writable)
   assert.isFalse(ws.readable)
 })
Example #14
0
 db.on("ready", function () {
   assert.isTrue(db.isOpen())
   done()
 })
Example #15
0
 levelup(this.cleanupDirs[0], { errorIfExists: false }, function (err, db) {
   refute(err)
   this.closeableDatabases.push(db)
   assert.isTrue(db.isOpen())
   done()
 }.bind(this))
Example #16
0
        it("returns true for an object with nested matcher", function () {
            var match = sinonMatch({outer: sinonMatch({ inner: "sinon" })});

            assert.isTrue(match.test({outer: { inner: "sinon", foo: "bar" }}));
        });
Example #17
0
 db.on('ready', function () {
   assert.isTrue(db.isOpen())
   done()
 })