diff options
author | Scott Hernandez <scotthernandez@gmail.com> | 2013-07-09 00:15:42 -0400 |
---|---|---|
committer | Scott Hernandez <scotthernandez@gmail.com> | 2013-07-09 00:16:05 -0400 |
commit | 2dff1cb34284427ecec2028e61000ad7d4cd6947 (patch) | |
tree | 2707cde4ea0e6517e4a653cd251e517b2769bc42 | |
parent | af45cb2615d13f1a29627ce2937633361413c797 (diff) | |
download | mongo-2dff1cb34284427ecec2028e61000ad7d4cd6947.tar.gz |
SERVER-7174: cleanup tests, + use assert.docEq for doc compares
-rw-r--r-- | jstests/rename4.js | 174 | ||||
-rw-r--r-- | jstests/server5346.js | 5 | ||||
-rw-r--r-- | jstests/update6.js | 2 | ||||
-rw-r--r-- | jstests/update_blank1.js | 2 | ||||
-rw-r--r-- | jstests/updateb.js | 2 | ||||
-rw-r--r-- | jstests/updatec.js | 2 | ||||
-rw-r--r-- | jstests/updated.js | 6 | ||||
-rw-r--r-- | jstests/updatek.js | 6 |
8 files changed, 104 insertions, 95 deletions
diff --git a/jstests/rename4.js b/jstests/rename4.js index 29be3744c88..2632a90424d 100644 --- a/jstests/rename4.js +++ b/jstests/rename4.js @@ -1,105 +1,117 @@ t = db.jstests_rename4; t.drop(); -function c( f ) { - assert( !db.getLastError(), "error" ); +function bad( f ) { + //Ensure no error to start with + var lstError = db.getLastError(); + if (lstError) + assert( false, "Unexpected error : " + lstError ); + eval( f ); - assert( db.getLastError(), "no error" ); + + //Ensure error + var lstError = db.getLastError(); + if (!lstError) { + print("Existing docs") + printjson(t.find().toArray()); + assert( false, "Expected error but didn't get one for: " + f ); + } + db.resetError(); } -c( "t.update( {}, {$rename:{'a':'a'}} )" ); -c( "t.update( {}, {$rename:{'':'a'}} )" ); -c( "t.update( {}, {$rename:{'a':''}} )" ); -c( "t.update( {}, {$rename:{'_id':'a'}} )" ); -c( "t.update( {}, {$rename:{'a':'_id'}} )" ); -c( "t.update( {}, {$rename:{'_id.a':'b'}} )" ); -c( "t.update( {}, {$rename:{'b':'_id.a'}} )" ); -c( "t.update( {}, {$rename:{'_id.a':'_id.b'}} )" ); -c( "t.update( {}, {$rename:{'_id.b':'_id.a'}} )" ); -c( "t.update( {}, {$rename:{'.a':'b'}} )" ); -c( "t.update( {}, {$rename:{'a':'.b'}} )" ); -c( "t.update( {}, {$rename:{'a.':'b'}} )" ); -c( "t.update( {}, {$rename:{'a':'b.'}} )" ); -c( "t.update( {}, {$rename:{'a.b':'a'}} )" ); -c( "t.update( {}, {$rename:{'a.$':'b'}} )" ); -c( "t.update( {}, {$rename:{'a':'b.$'}} )" ); -c( "t.update( {}, {$set:{b:1},$rename:{'a':'b'}} )" ); -c( "t.update( {}, {$rename:{'a':'b'},$set:{b:1}} )" ); -c( "t.update( {}, {$rename:{'a':'b'},$set:{a:1}} )" ); -c( "t.update( {}, {$set:{'b.c':1},$rename:{'a':'b'}} )" ); -c( "t.update( {}, {$set:{b:1},$rename:{'a':'b.c'}} )" ); -c( "t.update( {}, {$rename:{'a':'b'},$set:{'b.c':1}} )" ); -c( "t.update( {}, {$rename:{'a':'b.c'},$set:{b:1}} )" ); +bad( "t.update( {}, {$rename:{'a':'a'}} )" ); +bad( "t.update( {}, {$rename:{'':'a'}} )" ); +bad( "t.update( {}, {$rename:{'a':''}} )" ); +bad( "t.update( {}, {$rename:{'_id':'a'}} )" ); +bad( "t.update( {}, {$rename:{'a':'_id'}} )" ); +bad( "t.update( {}, {$rename:{'_id.a':'b'}} )" ); +bad( "t.update( {}, {$rename:{'b':'_id.a'}} )" ); +bad( "t.update( {}, {$rename:{'_id.a':'_id.b'}} )" ); +bad( "t.update( {}, {$rename:{'_id.b':'_id.a'}} )" ); +bad( "t.update( {}, {$rename:{'.a':'b'}} )" ); +bad( "t.update( {}, {$rename:{'a':'.b'}} )" ); +bad( "t.update( {}, {$rename:{'a.':'b'}} )" ); +bad( "t.update( {}, {$rename:{'a':'b.'}} )" ); +bad( "t.update( {}, {$rename:{'a.b':'a'}} )" ); +bad( "t.update( {}, {$rename:{'a.$':'b'}} )" ); +bad( "t.update( {}, {$rename:{'a':'b.$'}} )" ); +bad( "t.update( {}, {$set:{b:1},$rename:{'a':'b'}} )" ); +bad( "t.update( {}, {$rename:{'a':'b'},$set:{b:1}} )" ); +bad( "t.update( {}, {$rename:{'a':'b'},$set:{a:1}} )" ); +bad( "t.update( {}, {$set:{'b.c':1},$rename:{'a':'b'}} )" ); +bad( "t.update( {}, {$set:{b:1},$rename:{'a':'b.c'}} )" ); +bad( "t.update( {}, {$rename:{'a':'b'},$set:{'b.c':1}} )" ); +bad( "t.update( {}, {$rename:{'a':'b.c'},$set:{b:1}} )" ); t.save( {a:[1],b:{c:[1]},d:[{e:1}],f:1} ); -c( "t.update( {}, {$rename:{'a.0':'f'}} )" ); -c( "t.update( {}, {$rename:{'a.0':'g'}} )" ); -c( "t.update( {}, {$rename:{'f':'a.0'}} )" ); -c( "t.update( {}, {$rename:{'b.c.0':'f'}} )" ); -c( "t.update( {}, {$rename:{'f':'b.c.0'}} )" ); -c( "t.update( {}, {$rename:{'d.e':'d.f'}} )" ); -c( "t.update( {}, {$rename:{'d.e':'f'}} )" ); -c( "t.update( {}, {$rename:{'d.f':'d.e'}} )" ); -c( "t.update( {}, {$rename:{'f':'d.e'}} )" ); -c( "t.update( {}, {$rename:{'d.0.e':'d.f'}} )" ); -c( "t.update( {}, {$rename:{'d.0.e':'f'}} )" ); -c( "t.update( {}, {$rename:{'d.f':'d.0.e'}} )" ); -c( "t.update( {}, {$rename:{'f':'d.0.e'}} )" ); -c( "t.update( {}, {$rename:{'f.g':'a'}} )" ); -c( "t.update( {}, {$rename:{'a':'f.g'}} )" ); +bad( "t.update( {}, {$rename:{'a.0':'f'}} )" ); +bad( "t.update( {}, {$rename:{'a.0':'g'}} )" ); +bad( "t.update( {}, {$rename:{'f':'a.0'}} )" ); +bad( "t.update( {}, {$rename:{'b.c.0':'f'}} )" ); +bad( "t.update( {}, {$rename:{'f':'b.c.0'}} )" ); +bad( "t.update( {}, {$rename:{'d.e':'d.f'}} )" ); +bad( "t.update( {}, {$rename:{'d.e':'f'}} )" ); +bad( "t.update( {}, {$rename:{'d.f':'d.e'}} )" ); +bad( "t.update( {}, {$rename:{'f':'d.e'}} )" ); +bad( "t.update( {}, {$rename:{'d.0.e':'d.f'}} )" ); +bad( "t.update( {}, {$rename:{'d.0.e':'f'}} )" ); +bad( "t.update( {}, {$rename:{'d.f':'d.0.e'}} )" ); +bad( "t.update( {}, {$rename:{'f':'d.0.e'}} )" ); +bad( "t.update( {}, {$rename:{'f.g':'a'}} )" ); +bad( "t.update( {}, {$rename:{'a':'f.g'}} )" ); -function v( start, mod, expected ) { +function good( start, mod, expected ) { t.remove(); t.save( start ); t.update( {}, mod ); assert( !db.getLastError() ); var got = t.findOne(); delete got._id; - assert.eq( expected, got ); + assert.docEq( expected, got ); } -v( {a:1}, {$rename:{a:'b'}}, {b:1} ); -v( {a:1}, {$rename:{a:'bb'}}, {bb:1} ); -v( {b:1}, {$rename:{b:'a'}}, {a:1} ); -v( {bb:1}, {$rename:{bb:'a'}}, {a:1} ); -v( {a:{y:1}}, {$rename:{'a.y':'a.z'}}, {a:{z:1}} ); -v( {a:{yy:1}}, {$rename:{'a.yy':'a.z'}}, {a:{z:1}} ); -v( {a:{z:1}}, {$rename:{'a.z':'a.y'}}, {a:{y:1}} ); -v( {a:{zz:1}}, {$rename:{'a.zz':'a.y'}}, {a:{y:1}} ); -v( {a:{c:1}}, {$rename:{a:'b'}}, {b:{c:1}} ); -v( {aa:{c:1}}, {$rename:{aa:'b'}}, {b:{c:1}} ); -v( {a:1,b:2}, {$rename:{a:'b'}}, {b:1} ); -v( {aa:1,b:2}, {$rename:{aa:'b'}}, {b:1} ); -v( {a:1,bb:2}, {$rename:{a:'bb'}}, {bb:1} ); -v( {a:1}, {$rename:{a:'b.c'}}, {b:{c:1}} ); -v( {aa:1}, {$rename:{aa:'b.c'}}, {b:{c:1}} ); -v( {a:1,b:{}}, {$rename:{a:'b.c'}}, {b:{c:1}} ); -v( {aa:1,b:{}}, {$rename:{aa:'b.c'}}, {b:{c:1}} ); -v( {a:1}, {$rename:{b:'c'}}, {a:1} ); -v( {aa:1}, {$rename:{b:'c'}}, {aa:1} ); -v( {}, {$rename:{b:'c'}}, {} ); -v( {a:{b:1,c:2}}, {$rename:{'a.b':'d'}}, {a:{c:2},d:1} ); -v( {a:{bb:1,c:2}}, {$rename:{'a.bb':'d'}}, {a:{c:2},d:1} ); -v( {a:{b:1}}, {$rename:{'a.b':'d'}}, {a:{},d:1} ); -v( {a:[5]}, {$rename:{a:'b'}}, {b:[5]} ); -v( {aa:[5]}, {$rename:{aa:'b'}}, {b:[5]} ); -v( {'0':1}, {$rename:{'0':'5'}}, {'5':1} ); -v( {a:1,b:2}, {$rename:{a:'c'},$set:{b:5}}, {b:5,c:1} ); -v( {aa:1,b:2}, {$rename:{aa:'c'},$set:{b:5}}, {b:5,c:1} ); -v( {a:1,b:2}, {$rename:{z:'c'},$set:{b:5}}, {a:1,b:5} ); -v( {aa:1,b:2}, {$rename:{z:'c'},$set:{b:5}}, {aa:1,b:5} ); +good( {a:1}, {$rename:{a:'b'}}, {b:1} ); +good( {a:1}, {$rename:{a:'bb'}}, {bb:1} ); +good( {b:1}, {$rename:{b:'a'}}, {a:1} ); +good( {bb:1}, {$rename:{bb:'a'}}, {a:1} ); +good( {a:{y:1}}, {$rename:{'a.y':'a.z'}}, {a:{z:1}} ); +good( {a:{yy:1}}, {$rename:{'a.yy':'a.z'}}, {a:{z:1}} ); +good( {a:{z:1}}, {$rename:{'a.z':'a.y'}}, {a:{y:1}} ); +good( {a:{zz:1}}, {$rename:{'a.zz':'a.y'}}, {a:{y:1}} ); +good( {a:{c:1}}, {$rename:{a:'b'}}, {b:{c:1}} ); +good( {aa:{c:1}}, {$rename:{aa:'b'}}, {b:{c:1}} ); +good( {a:1,b:2}, {$rename:{a:'b'}}, {b:1} ); +good( {aa:1,b:2}, {$rename:{aa:'b'}}, {b:1} ); +good( {a:1,bb:2}, {$rename:{a:'bb'}}, {bb:1} ); +good( {a:1}, {$rename:{a:'b.c'}}, {b:{c:1}} ); +good( {aa:1}, {$rename:{aa:'b.c'}}, {b:{c:1}} ); +good( {a:1,b:{}}, {$rename:{a:'b.c'}}, {b:{c:1}} ); +good( {aa:1,b:{}}, {$rename:{aa:'b.c'}}, {b:{c:1}} ); +good( {a:1}, {$rename:{b:'c'}}, {a:1} ); +good( {aa:1}, {$rename:{b:'c'}}, {aa:1} ); +good( {}, {$rename:{b:'c'}}, {} ); +good( {a:{b:1,c:2}}, {$rename:{'a.b':'d'}}, {a:{c:2},d:1} ); +good( {a:{bb:1,c:2}}, {$rename:{'a.bb':'d'}}, {a:{c:2},d:1} ); +good( {a:{b:1}}, {$rename:{'a.b':'d'}}, {a:{},d:1} ); +good( {a:[5]}, {$rename:{a:'b'}}, {b:[5]} ); +good( {aa:[5]}, {$rename:{aa:'b'}}, {b:[5]} ); +good( {'0':1}, {$rename:{'0':'5'}}, {'5':1} ); +good( {a:1,b:2}, {$rename:{a:'c'},$set:{b:5}}, {b:5,c:1} ); +good( {aa:1,b:2}, {$rename:{aa:'c'},$set:{b:5}}, {b:5,c:1} ); +good( {a:1,b:2}, {$rename:{z:'c'},$set:{b:5}}, {a:1,b:5} ); +good( {aa:1,b:2}, {$rename:{z:'c'},$set:{b:5}}, {aa:1,b:5} ); // (formerly) rewriting single field -v( {a:{z:1,b:1}}, {$rename:{'a.b':'a.c'}}, {a:{c:1,z:1}} ); -v( {a:{z:1,tomato:1}}, {$rename:{'a.tomato':'a.potato'}}, {a:{potato:1,z:1}} ); -v( {a:{z:1,b:1,c:1}}, {$rename:{'a.b':'a.c'}}, {a:{c:1,z:1}} ); -v( {a:{z:1,tomato:1,potato:1}}, {$rename:{'a.tomato':'a.potato'}}, {a:{potato:1,z:1}} ); -v( {a:{z:1,b:1}}, {$rename:{'a.b':'a.cc'}}, {a:{cc:1,z:1}} ); -v( {a:{z:1,b:1,c:1}}, {$rename:{'a.b':'aa.c'}}, {a:{c:1,z:1},aa:{c:1}} ); +good( {a:{z:1,b:1}}, {$rename:{'a.b':'a.c'}}, {a:{c:1,z:1}} ); +good( {a:{z:1,tomato:1}}, {$rename:{'a.tomato':'a.potato'}}, {a:{potato:1,z:1}} ); +good( {a:{z:1,b:1,c:1}}, {$rename:{'a.b':'a.c'}}, {a:{c:1,z:1}} ); +good( {a:{z:1,tomato:1,potato:1}}, {$rename:{'a.tomato':'a.potato'}}, {a:{potato:1,z:1}} ); +good( {a:{z:1,b:1}}, {$rename:{'a.b':'a.cc'}}, {a:{cc:1,z:1}} ); +good( {a:{z:1,b:1,c:1}}, {$rename:{'a.b':'aa.c'}}, {a:{c:1,z:1},aa:{c:1}} ); // invalid target, but missing source -v( {a:1,c:4}, {$rename:{b:'c.d'}}, {a:1,c:4} ); +good( {a:1,c:4}, {$rename:{b:'c.d'}}, {a:1,c:4} ); // check index t.drop(); @@ -112,7 +124,7 @@ function l( start, mod, query, expected ) { assert( !db.getLastError() ); var got = t.find( query ).hint( {a:1} ).next(); delete got._id; - assert.eq( expected, got ); + assert.docEq( expected, got ); } l( {a:1}, {$rename:{a:'b'}}, {a:null}, {b:1} ); diff --git a/jstests/server5346.js b/jstests/server5346.js index f90d6b579c2..f4a692bd16a 100644 --- a/jstests/server5346.js +++ b/jstests/server5346.js @@ -11,6 +11,5 @@ t.update({ _id : 1 }, { $inc : { "versions.01" : 3 } } ) t.update({ _id : 1 }, { $inc : { "versions.1" : 4 } } ) // Make sure the correct fields are set, without duplicates. -// String comparison must be used because V8 reorders numeric fields in objects. -assert.eq( '{ "_id" : 1, "versions" : { "01" : 3, "1" : 4, "2_01" : 1, "2_1" : 2 } }' , - tojson( t.findOne(), null, true ) ) +assert.docEq( { "_id" : 1, "versions" : { "01" : 3, "1" : 4, "2_01" : 1, "2_1" : 2 } }, + t.findOne()) diff --git a/jstests/update6.js b/jstests/update6.js index 1f42fe5dead..05fc5b223d9 100644 --- a/jstests/update6.js +++ b/jstests/update6.js @@ -10,7 +10,7 @@ assert.eq( "c,d" , Object.keySet( t.findOne().b ).toString() , "B" ); t.update( { a : 1 } , { $inc : { "b.0e" : 1 } } ); assert.eq( 1 , t.findOne().b["0e"] , "C" ); -assert.eq( "0e,c,d" , Object.keySet( t.findOne().b ).toString() , "D" ); +assert.docEq( { "c" : 2, "d" : 1, "0e" : 1 }, t.findOne().b, "D" ); // ----- diff --git a/jstests/update_blank1.js b/jstests/update_blank1.js index 846b8a2b46a..a2344035dc3 100644 --- a/jstests/update_blank1.js +++ b/jstests/update_blank1.js @@ -7,4 +7,4 @@ t.insert( orig ); t.update( {} , { $set : { "c" : 5 } } ); print( db.getLastError() ); orig["c"] = 5; -assert.eq( orig , t.findOne() , "after $set" ); // SERVER-2651 +assert.docEq( orig , t.findOne() , "after $set" ); // SERVER-2651
\ No newline at end of file diff --git a/jstests/updateb.js b/jstests/updateb.js index ee7c531052f..d85e19a36bc 100644 --- a/jstests/updateb.js +++ b/jstests/updateb.js @@ -7,5 +7,5 @@ t.update( { "x.y" : 2 } , { $inc : { a : 7 } } , true ); correct = { a : 7 , x : { y : 2 } }; got = t.findOne(); delete got._id; -assert.eq( correct , got , "A" ) +assert.docEq( correct , got , "A" ) diff --git a/jstests/updatec.js b/jstests/updatec.js index 12b1325f921..0c77b8b3cda 100644 --- a/jstests/updatec.js +++ b/jstests/updatec.js @@ -5,7 +5,7 @@ t.drop(); t.update( { "_id" : 123 }, { $set : { "v" : { "i" : 123, "a":456 } }, $push : { "f" : 234} }, 1, 0 ); t.update( { "_id" : 123 }, { $set : { "v" : { "i" : 123, "a":456 } }, $push : { "f" : 234} }, 1, 0 ); -assert.eq( +assert.docEq( { "_id" : 123, "f" : [ 234, 234 ] , diff --git a/jstests/updated.js b/jstests/updated.js index c4c11bee8ea..c202e8d435f 100644 --- a/jstests/updated.js +++ b/jstests/updated.js @@ -7,14 +7,14 @@ o = { _id : Math.random() , }; t.insert( o ); -assert.eq( o , t.findOne() , "A1" ); +assert.docEq( o , t.findOne() , "A1" ); o.items[0] = {amount:9000,itemId:1}; t.update({},{$set:{"items.0":o.items[0]}}); -assert.eq( o , t.findOne() , "A2" ); +assert.docEq( o , t.findOne() , "A2" ); o.items[0].amount += 1000; o.items[1] = {amount:1,itemId:2}; t.update({},{$inc:{"items.0.amount":1000},$set:{"items.1":o.items[1]}}); -assert.eq( o , t.findOne() , "A3" ); +assert.docEq( o , t.findOne() , "A3" ); diff --git a/jstests/updatek.js b/jstests/updatek.js index 0c6c848ab16..b96f3138a81 100644 --- a/jstests/updatek.js +++ b/jstests/updatek.js @@ -5,12 +5,10 @@ t = db.jstests_updatek; t.drop(); t.save( { _id:0, '1':{}, '01':{} } ); t.update( {}, { $set:{ '1.b':1, '1.c':2 } } ); -// make sure correct fields are set, with no duplicates -// must use string comparison because V8 reorders fields that are numerical in objects -assert.eq( "{ \"01\" : { }, \"1\" : { \"b\" : 1, \"c\" : 2 }, \"_id\" : 0 }", tojson(t.findOne()) ); +assert.docEq( { "01" : { }, "1" : { "b" : 1, "c" : 2 }, "_id" : 0 }, t.findOne() ); t.drop(); t.save( { _id:0, '1':{}, '01':{} } ); t.update( {}, { $set:{ '1.b':1, '01.c':2 } } ); -assert.eq( "{ \"01\" : { \"c\" : 2 }, \"1\" : { \"b\" : 1 }, \"_id\" : 0 }", tojson(t.findOne()) ); +assert.docEq( { "01" : { "c" : 2 }, "1" : { "b" : 1 }, "_id" : 0 }, t.findOne() ); |