TEST( UpdateIndexDataTest, Simple2 ) { UpdateIndexData a; a.addPath( "ab" ); ASSERT_FALSE( a.mightBeIndexed( "a" ) ); a.clear(); ASSERT_FALSE( a.mightBeIndexed( "ab" ) ); }
TEST( UpdateIndexDataTest, AllPathsIndexed1 ) { UpdateIndexData a; a.allPathsIndexed(); ASSERT_TRUE( a.mightBeIndexed( "a" ) ); a.clear(); ASSERT_FALSE( a.mightBeIndexed( "a" ) ); }
TEST( UpdateIndexDataTest, Component1 ) { UpdateIndexData a; a.addPathComponent( "a" ); ASSERT_FALSE( a.mightBeIndexed( "" ) ); ASSERT_TRUE( a.mightBeIndexed( "a" ) ); ASSERT_TRUE( a.mightBeIndexed( "b.a" ) ); ASSERT_TRUE( a.mightBeIndexed( "a.b" ) ); ASSERT_TRUE( a.mightBeIndexed( "b.a.c" ) ); ASSERT_FALSE( a.mightBeIndexed( "b.c" ) ); ASSERT_FALSE( a.mightBeIndexed( "ab" ) ); a.clear(); ASSERT_FALSE( a.mightBeIndexed( "a" ) ); }
TEST( UpdateIndexDataTest, Simple1 ) { UpdateIndexData a; a.addPath( "a.b" ); ASSERT_TRUE( a.mightBeIndexed( "a.b" ) ); ASSERT_TRUE( a.mightBeIndexed( "a" ) ); ASSERT_TRUE( a.mightBeIndexed( "a.b.c" ) ); ASSERT_TRUE( a.mightBeIndexed( "a.$.b" ) ); ASSERT_FALSE( a.mightBeIndexed( "b" ) ); ASSERT_FALSE( a.mightBeIndexed( "a.c" ) ); a.clear(); ASSERT_FALSE( a.mightBeIndexed( "a.b" ) ); }
TEST( UpdateIndexDataTest, AllPathsIndexed2 ) { UpdateIndexData a; a.allPathsIndexed(); ASSERT_TRUE( a.mightBeIndexed( "a" ) ); ASSERT_TRUE( a.mightBeIndexed( "" ) ); a.addPathComponent( "a" ); ASSERT_TRUE( a.mightBeIndexed( "a" ) ); ASSERT_TRUE( a.mightBeIndexed( "b" ) ); a.clear(); ASSERT_FALSE( a.mightBeIndexed( "a" ) ); }
TEST_F(CurrentDateNodeTest, ApplyIndexesNotAffected) { auto update = fromjson("{$currentDate: {a: true}}"); const CollatorInterface* collator = nullptr; CurrentDateNode node; ASSERT_OK(node.init(update["$currentDate"]["a"], collator)); Document doc(fromjson("{a: 0}")); FieldRef pathToCreate(""); FieldRef pathTaken("a"); StringData matchedField; auto fromReplication = true; auto validateForStorage = true; FieldRefSet immutablePaths; UpdateIndexData indexData; indexData.addPath("b"); Document logDoc; LogBuilder logBuilder(logDoc.root()); auto indexesAffected = false; auto noop = false; node.apply(doc.root()["a"], &pathToCreate, &pathTaken, matchedField, fromReplication, validateForStorage, immutablePaths, &indexData, &logBuilder, &indexesAffected, &noop); ASSERT_FALSE(noop); ASSERT_FALSE(indexesAffected); ASSERT_EQUALS(doc.root().countChildren(), 1U); ASSERT_TRUE(doc.root()["a"].ok()); ASSERT_EQUALS(doc.root()["a"].getType(), BSONType::Date); ASSERT_EQUALS(logDoc.root().countChildren(), 1U); ASSERT_TRUE(logDoc.root()["$set"].ok()); ASSERT_EQUALS(logDoc.root()["$set"].countChildren(), 1U); ASSERT_TRUE(logDoc.root()["$set"]["a"].ok()); ASSERT_EQUALS(logDoc.root()["$set"]["a"].getType(), BSONType::Date); }
TEST(AddToSetNodeTest, ApplyRespectsCollationFromSetCollator) { auto update = fromjson("{$addToSet: {a: {$each: ['abc', 'ABC', 'def', 'abc']}}}"); const CollatorInterface* binaryComparisonCollator = nullptr; AddToSetNode node; ASSERT_OK(node.init(update["$addToSet"]["a"], binaryComparisonCollator)); const CollatorInterfaceMock caseInsensitiveCollator( CollatorInterfaceMock::MockType::kToLowerString); node.setCollator(&caseInsensitiveCollator); Document doc(fromjson("{a: []}")); FieldRef pathToCreate(""); FieldRef pathTaken("a"); StringData matchedField; auto fromReplication = true; auto validateForStorage = true; FieldRefSet immutablePaths; UpdateIndexData indexData; indexData.addPath("a"); Document logDoc; LogBuilder logBuilder(logDoc.root()); auto indexesAffected = false; auto noop = false; node.apply(doc.root()["a"], &pathToCreate, &pathTaken, matchedField, fromReplication, validateForStorage, immutablePaths, &indexData, &logBuilder, &indexesAffected, &noop); ASSERT_FALSE(noop); ASSERT_TRUE(indexesAffected); ASSERT_EQUALS(fromjson("{a: ['abc', 'def']}"), doc); ASSERT_FALSE(doc.isInPlaceModeEnabled()); ASSERT_EQUALS(fromjson("{$set: {a: ['abc', 'def']}}"), logDoc); }
TEST(AddToSetNodeTest, ApplyCreateEmptyArrayIsNotNoop) { auto update = fromjson("{$addToSet: {a: {$each: []}}}"); const CollatorInterface* collator = nullptr; AddToSetNode node; ASSERT_OK(node.init(update["$addToSet"]["a"], collator)); Document doc(fromjson("{}")); FieldRef pathToCreate("a"); FieldRef pathTaken(""); StringData matchedField; auto fromReplication = true; auto validateForStorage = true; FieldRefSet immutablePaths; UpdateIndexData indexData; indexData.addPath("a"); Document logDoc; LogBuilder logBuilder(logDoc.root()); auto indexesAffected = false; auto noop = false; node.apply(doc.root(), &pathToCreate, &pathTaken, matchedField, fromReplication, validateForStorage, immutablePaths, &indexData, &logBuilder, &indexesAffected, &noop); ASSERT_FALSE(noop); ASSERT_TRUE(indexesAffected); ASSERT_EQUALS(fromjson("{a: []}"), doc); ASSERT_FALSE(doc.isInPlaceModeEnabled()); ASSERT_EQUALS(fromjson("{$set: {a: []}}"), logDoc); }