summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/aggregation_context_fixture.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/aggregation_context_fixture.h')
-rw-r--r--src/mongo/db/pipeline/aggregation_context_fixture.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/aggregation_context_fixture.h b/src/mongo/db/pipeline/aggregation_context_fixture.h
index a4dfcfeb769..cce0283314c 100644
--- a/src/mongo/db/pipeline/aggregation_context_fixture.h
+++ b/src/mongo/db/pipeline/aggregation_context_fixture.h
@@ -31,8 +31,10 @@
#include <boost/intrusive_ptr.hpp>
#include <memory>
+#include <vector>
#include "mongo/db/concurrency/locker_noop_client_observer.h"
+#include "mongo/db/pipeline/document_source.h"
#include "mongo/db/pipeline/expression_context_for_test.h"
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/unittest/temp_dir.h"
@@ -71,6 +73,42 @@ public:
return _opCtx.get();
}
+ /*
+ * Serialize and redact a document source.
+ */
+ BSONObj redact(const DocumentSource& docSource,
+ bool performRedaction = true,
+ boost::optional<ExplainOptions::Verbosity> verbosity = boost::none) {
+ SerializationOptions options;
+ options.verbosity = verbosity;
+ if (performRedaction) {
+ options.literalPolicy = LiteralSerializationPolicy::kToDebugTypeString;
+ options.transformIdentifiersCallback = [](StringData s) -> std::string {
+ return str::stream() << "HASH<" << s << ">";
+ };
+ options.transformIdentifiers = true;
+ }
+ std::vector<Value> serialized;
+ docSource.serializeToArray(serialized, options);
+ ASSERT_EQ(1, serialized.size());
+ return serialized[0].getDocument().toBson().getOwned();
+ }
+
+ std::vector<Value> redactToArray(const DocumentSource& docSource,
+ bool performRedaction = true) {
+ SerializationOptions options;
+ if (performRedaction) {
+ options.literalPolicy = LiteralSerializationPolicy::kToDebugTypeString;
+ options.transformIdentifiersCallback = [](StringData s) -> std::string {
+ return str::stream() << "HASH<" << s << ">";
+ };
+ options.transformIdentifiers = true;
+ }
+ std::vector<Value> serialized;
+ docSource.serializeToArray(serialized, options);
+ return serialized;
+ }
+
private:
ServiceContext::UniqueOperationContext _opCtx;
boost::intrusive_ptr<ExpressionContextForTest> _expCtx;