diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-01-26 22:50:27 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-26 23:43:54 +0000 |
commit | 90239f246867eb632ad03520dbe6856af50e5c7e (patch) | |
tree | 4e3c0c2853168f8191010194216d0bae8f6f2b92 /src/mongo/idl | |
parent | 9b3c10f0baba2522c37db5dfdb1d41c78522c20b (diff) | |
download | mongo-90239f246867eb632ad03520dbe6856af50e5c7e.tar.gz |
SERVER-63002 Support bindata types for variants in IDL
Diffstat (limited to 'src/mongo/idl')
-rw-r--r-- | src/mongo/idl/idl_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/idl/unittest.idl | 16 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp index 1b814c7147d..4a1d30f422c 100644 --- a/src/mongo/idl/idl_test.cpp +++ b/src/mongo/idl/idl_test.cpp @@ -476,6 +476,8 @@ void TestLoopbackVariant(TestT test_value) { arrayBuilder.append(item); } } + } else if constexpr (std::is_same_v<TestT, UUID>) { + test_value.appendToBuilder(&bob, "value"); } else { bob.append("value", test_value); } @@ -512,6 +514,9 @@ TEST(IDLVariantTests, TestVariantRoundtrip) { TestLoopbackVariant<One_variant, int, NumberInt>(1); TestLoopbackVariant<One_variant, std::string, String>("test_value"); + TestLoopbackVariant<One_variant_uuid, int, NumberInt>(1); + TestLoopbackVariant<One_variant_uuid, UUID, BinData>(UUID::gen()); + TestLoopbackVariant<One_variant_compound, std::string, String>("test_value"); TestLoopbackVariant<One_variant_compound, BSONObj, Object>(BSON("x" << 1)); TestLoopbackVariant<One_variant_compound, std::vector<std::string>, Array>({}); @@ -2561,6 +2566,8 @@ void TestLoopbackCommandTypeVariant(TestT test_value) { // TestT might be an IDL struct type like One_string. BSONObjBuilder subObj(bob.subobjStart(CommandT::kCommandParameterFieldName)); test_value.serialize(&subObj); + } else if constexpr (std::is_same_v<TestT, UUID>) { + test_value.appendToBuilder(&bob, CommandT::kCommandParameterFieldName); } else { bob.append(CommandT::kCommandParameterFieldName, test_value); } @@ -2596,6 +2603,9 @@ TEST(IDLCommand, TestCommandTypeVariant) { TestLoopbackCommandTypeVariant<CommandTypeVariantCommand, std::vector<std::string>, Array>( {"x", "y"}); + TestLoopbackCommandTypeVariant<CommandTypeVariantUUIDCommand, int, NumberInt>(1); + TestLoopbackCommandTypeVariant<CommandTypeVariantUUIDCommand, UUID, BinData>(UUID::gen()); + TestLoopbackCommandTypeVariant<CommandTypeVariantStructCommand, bool, Bool>(true); TestLoopbackCommandTypeVariant<CommandTypeVariantStructCommand, One_string, Object>( One_string("test_value")); diff --git a/src/mongo/idl/unittest.idl b/src/mongo/idl/unittest.idl index 9d3bd42e70f..9f1ac12b029 100644 --- a/src/mongo/idl/unittest.idl +++ b/src/mongo/idl/unittest.idl @@ -637,6 +637,14 @@ structs: type: variant: [safeInt, string] + one_variant_uuid: + description: UnitTest for a single variant with a bindata type + strict: false + fields: + value: + type: + variant: [int, uuid] + one_variant_compound: description: UnitTest for a single variant which accepts string, doc, or array of string strict: false @@ -997,6 +1005,14 @@ commands: type: variant: [int, string, array<string>] + CommandTypeVariantUUIDCommand: + description: Command with a variant parameter that can be a bindata type + command_name: CommandTypeVariantCommand + namespace: type + api_version: "" + type: + variant: [int, uuid] + CommandTypeVariantStructCommand: description: Command with a variant parameter that can be a struct command_name: CommandTypeVariantStructCommand |