mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-30 00:56:44 +01:00
More push tests
This commit is contained in:
parent
47340a0a9b
commit
835506af0a
@ -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 >();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user