diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2014-02-19 12:45:53 -0500 |
---|---|---|
committer | Matt Kangas <matt.kangas@mongodb.com> | 2014-03-03 22:54:10 -0500 |
commit | 3660343e0b4627d2fee4afb89b74d32644d16d18 (patch) | |
tree | ffa571e0b73ce56d73c2ae23f458f0db772ef782 /jstests/core/uniqueness.js | |
parent | 9fae141a1f3fe652fa6002e47722c5ceb051cffb (diff) | |
download | mongo-3660343e0b4627d2fee4afb89b74d32644d16d18.tar.gz |
SERVER-12127 migrate js tests to jscore suite when not related to writes
Migrate js tests starting from j-z.
Include SERVER-12920 Update use_power_of_2.js
Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Diffstat (limited to 'jstests/core/uniqueness.js')
-rw-r--r-- | jstests/core/uniqueness.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/jstests/core/uniqueness.js b/jstests/core/uniqueness.js new file mode 100644 index 00000000000..56107e7ce25 --- /dev/null +++ b/jstests/core/uniqueness.js @@ -0,0 +1,56 @@ +var res; + +t = db.jstests_uniqueness; + +t.drop(); + +// test uniqueness of _id + +res = t.save( { _id : 3 } ); +assert.writeOK( res ); + +// this should yield an error +res = t.insert( { _id : 3 } ); +assert.writeError( res ); +assert( t.count() == 1, "hmmm"); + +res = t.insert( { _id : 4, x : 99 } ); +assert.writeOK( res ); + +// this should yield an error +res = t.update( { _id : 4 } , { _id : 3, x : 99 } ); +assert.writeError( res ); +assert( t.findOne( {_id:4} ), 5 ); + +// Check for an error message when we index and there are dups +db.jstests_uniqueness2.drop(); +db.jstests_uniqueness2.insert({a:3}); +db.jstests_uniqueness2.insert({a:3}); +assert( db.jstests_uniqueness2.count() == 2 , 6) ; +res = db.jstests_uniqueness2.ensureIndex({a:1}, true); +assert.writeError( res ); +assert( res.getWriteError().errmsg.match( /E11000/ ) ); + +// Check for an error message when we index in the background and there are dups +db.jstests_uniqueness2.drop(); +db.jstests_uniqueness2.insert({a:3}); +db.jstests_uniqueness2.insert({a:3}); +assert( db.jstests_uniqueness2.count() == 2 , 6) ; +res = db.jstests_uniqueness2.ensureIndex({a:1}, {unique:true,background:true}); +assert.writeError( res ); +assert( res.getWriteError().errmsg.match( /E11000/ ) ); + +/* Check that if we update and remove _id, it gets added back by the DB */ + +/* - test when object grows */ +t.drop(); +t.save( { _id : 'Z' } ); +t.update( {}, { k : 2 } ); +assert( t.findOne()._id == 'Z', "uniqueness.js problem with adding back _id" ); + +/* - test when doesn't grow */ +t.drop(); +t.save( { _id : 'Z', k : 3 } ); +t.update( {}, { k : 2 } ); +assert( t.findOne()._id == 'Z', "uniqueness.js problem with adding back _id (2)" ); + |