diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2018-04-04 15:11:07 +0100 |
---|---|---|
committer | Bernard Gorman <bernard.gorman@gmail.com> | 2018-04-05 03:02:23 +0100 |
commit | f00b908d2bf6cca4c2527eaa88b0ae79d745fd0b (patch) | |
tree | b610c3f40fa13af40190ae63aabec515f05b0378 /src/mongo/db/pipeline/document_source_change_stream_test.cpp | |
parent | c948a158d2ba4362906cc2b3cae9fa07b5e57ff4 (diff) | |
download | mongo-f00b908d2bf6cca4c2527eaa88b0ae79d745fd0b.tar.gz |
SERVER-34282 Ban change streams on entire database unless test commands are enabled
Diffstat (limited to 'src/mongo/db/pipeline/document_source_change_stream_test.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_change_stream_test.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp index 2b7661d3f58..32df8e68959 100644 --- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp @@ -35,6 +35,7 @@ #include "mongo/bson/json.h" #include "mongo/db/catalog/collection_mock.h" #include "mongo/db/catalog/uuid_catalog.h" +#include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/pipeline/aggregation_context_fixture.h" #include "mongo/db/pipeline/document.h" #include "mongo/db/pipeline/document_source.h" @@ -728,9 +729,35 @@ TEST_F(ChangeStreamStageTest, CloseCursorEvenIfInvalidateEntriesGetFilteredOut) class ChangeStreamStageDBTest : public ChangeStreamStageTest { public: ChangeStreamStageDBTest() - : ChangeStreamStageTest(NamespaceString::makeCollectionlessAggregateNSS(nss.db())) {} + : ChangeStreamStageTest(NamespaceString::makeCollectionlessAggregateNSS(nss.db())) { + setTestCommandsEnabled(true); + } }; +// TODO SERVER-34283: remove once whole-database $changeStream is feature-complete. +TEST_F(ChangeStreamStageDBTest, ShouldSucceedIfTestCommandsEnabled) { + const auto spec = fromjson("{$changeStream: {}}"); + + const auto stages = DSChangeStream::createFromBson(spec.firstElement(), getExpCtx()); + ASSERT_TRUE(dynamic_cast<DocumentSourceMatch*>(stages.front().get())); + ASSERT_EQUALS(stages.size(), 3UL); + + for (auto&& stage : stages) { + ASSERT_EQUALS(string(stage->getSourceName()), DSChangeStream::kStageName); + } +} + +// TODO SERVER-34283: remove once whole-database $changeStream is feature-complete. +TEST_F(ChangeStreamStageDBTest, ShouldFailIfTestCommandsDisabled) { + setTestCommandsEnabled(false); + + const auto spec = fromjson("{$changeStream: {}}"); + + ASSERT_THROWS_CODE(DSChangeStream::createFromBson(spec.firstElement(), getExpCtx()), + AssertionException, + ErrorCodes::QueryFeatureNotAllowed); +} + TEST_F(ChangeStreamStageDBTest, TransformInsert) { auto insert = makeOplogEntry(OpTypeEnum::kInsert, nss, BSON("_id" << 1 << "x" << 2)); |