var setup = require('./setup'),
    assert = require('assert');

setup.plan(2); // exit at second call to setup.end()

setup(function(err, cb) {
    assert(!err, "setup failure");

    cb.on("error", function (message) {
        console.log("ERROR: [" + message + "]");
        process.exit(1);
    });

    // test cas updates
    var testkey = "01-set.js"
    cb.set(testkey, "bar", function (err, meta) {
        assert(!err, "Failed to store object");
        assert.equal(testkey, meta.id, "Callback called with wrong key!")

        cb.set(testkey, "baz", meta, function(err, meta) {
            assert(!err, "Failed to set with cas");
            assert.equal(testkey, meta.id, "Callback called with wrong key!")
            // intentionally break the cas
            meta.cas.str = "123456789";
            cb.set(testkey, "bam", meta, function(err, meta) {
                assert(err, "Should error with cas mismatch");
                cb.get(testkey, function(err, doc) {
                    assert(!err, "Failed to load object");
                    assert.equal("baz", doc, "Document changed despite bad cas!")
                    setup.end()
                })
            })
        })
    });

    // test non cas updates
    var testkey2 = "01-set.js2"
    cb.set(testkey2, {foo : "bar"}, function (err, meta) {
        assert(!err, "Failed to store object");
        assert.equal(testkey2, meta.id, "Callback called with wrong key!")

        // non cas updates work too
        cb.set(testkey2, {foo : "baz"}, function(err, meta) {
            assert(!err, "Failed to set without cas");
            assert.equal(testkey2, meta.id, "Callback called with wrong key!")
            setup.end();
        })
    });
})

@@ -385,32 +385,37 @@
  function (err, 
+first
 meta) %7B%0A        
@@ -476,32 +476,37 @@
 .equal(testkey, 
+first
 meta.id, %22Callba
@@ -565,16 +565,21 @@
  %22baz%22, 
+first
 meta, fu
@@ -744,78 +744,134 @@
     
-// intentionally break the cas%0A            meta.cas.str = %22123456789%22;
+assert.notEqual(firstmeta.cas.str, meta.cas.str, %22cas should change%22);%0A            // use the old cas, should reject the write
 %0A   
@@ -902,16 +902,21 @@
  %22bam%22, 
+first
 meta, fu

update the set test to use cas properly