diff options
author | Aaron <aaron@10gen.com> | 2009-03-25 10:34:32 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-03-25 10:34:32 -0400 |
commit | 835506af0aeec1d42f840d4d02a0b35314a34498 (patch) | |
tree | a0b8128543d27cf41305ba64a6dfe411fc42756d /dbtests/updatetests.cpp | |
parent | 47340a0a9b7ee5787dd22392837a37cd2e9f652a (diff) | |
download | mongo-835506af0aeec1d42f840d4d02a0b35314a34498.tar.gz |
More push tests
Diffstat (limited to 'dbtests/updatetests.cpp')
-rw-r--r-- | dbtests/updatetests.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/dbtests/updatetests.cpp b/dbtests/updatetests.cpp index d82ea301229..5d00f44ce5f 100644 --- a/dbtests/updatetests.cpp +++ b/dbtests/updatetests.cpp @@ -337,6 +337,42 @@ namespace UpdateTests { } }; + class PushFromEmpty : public SetBase { + public: + void run() { + client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 5 ) ) ); + ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[5]}" ) ) == 0 ); + } + }; + + class PushInsideNothing : public SetBase { + public: + void run() { + client().insert( ns(), fromjson( "{'_id':0}" ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "a.b" << 5 ) ) ); + ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:[5]}}" ) ) == 0 ); + } + }; + + class CantPushInsideOtherMod : public SetBase { + public: + void run() { + client().insert( ns(), fromjson( "{'_id':0}" ) ); + client().update( ns(), Query(), BSON( "$set" << BSON( "a" << BSONObj() ) << "$push" << BSON( "a.b" << 5 ) ) ); + ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0}" ) ) == 0 ); + } + }; + + class CantPushTwice : public SetBase { + public: + void run() { + client().insert( ns(), fromjson( "{'_id':0,a:[]}" ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "a" << 4 ) << "$push" << BSON( "a" << 5 ) ) ); + ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:[]}" ) ) == 0 ); + } + }; + class All : public UnitTest::Suite { public: All() { @@ -371,6 +407,10 @@ namespace UpdateTests { add< PushInvalidEltType >(); add< PushConflictsWithOtherMod >(); add< PushFromNothing >(); + add< PushFromEmpty >(); + add< PushInsideNothing >(); + add< CantPushInsideOtherMod >(); + add< CantPushTwice >(); } }; |