summaryrefslogtreecommitdiff
path: root/src/mongo/db/keys_collection_document_test.cpp
diff options
context:
space:
mode:
authorCheahuychou Mao <mao.cheahuychou@gmail.com>2021-01-06 19:39:39 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-13 02:05:27 +0000
commit5c1c3e6930a5acefe1a1fbe2763db8e435167e26 (patch)
treebc5fe2aadf4c5fa76e55ec393967910a7102297a /src/mongo/db/keys_collection_document_test.cpp
parent34e32be7b869deea3fc100d4e60b08986fdc4528 (diff)
downloadmongo-5c1c3e6930a5acefe1a1fbe2763db8e435167e26.tar.gz
SERVER-53680 Use IDL for KeysCollectionDocument
Diffstat (limited to 'src/mongo/db/keys_collection_document_test.cpp')
-rw-r--r--src/mongo/db/keys_collection_document_test.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/mongo/db/keys_collection_document_test.cpp b/src/mongo/db/keys_collection_document_test.cpp
index dfa6124a212..6be5e268507 100644
--- a/src/mongo/db/keys_collection_document_test.cpp
+++ b/src/mongo/db/keys_collection_document_test.cpp
@@ -30,7 +30,8 @@
#include "mongo/platform/basic.h"
#include "mongo/db/jsobj.h"
-#include "mongo/db/keys_collection_document.h"
+#include "mongo/db/keys_collection_document_gen.h"
+#include "mongo/db/time_proof_service.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
@@ -52,10 +53,7 @@ TEST(KeysCollectionDocument, Roundtrip) {
KeysCollectionDocument keysCollectionDoc(keyId, purpose, key, expiresAt);
auto serializedObj = keysCollectionDoc.toBSON();
-
- auto parseStatus = KeysCollectionDocument::fromBSON(serializedObj);
- ASSERT_OK(parseStatus.getStatus());
- const auto& parsedKey = parseStatus.getValue();
+ auto parsedKey = KeysCollectionDocument::parse(IDLParserErrorContext("keyDoc"), serializedObj);
ASSERT_EQ(keyId, parsedKey.getKeyId());
ASSERT_EQ(purpose, parsedKey.getPurpose());
@@ -78,8 +76,10 @@ TEST(KeysCollectionDocument, MissingKeyIdShouldFailToParse) {
expiresAt.asTimestamp().append(builder.bb(), "expiresAt");
auto serializedObj = builder.done();
- auto status = KeysCollectionDocument::fromBSON(serializedObj).getStatus();
- ASSERT_EQ(ErrorCodes::NoSuchKey, status);
+ ASSERT_THROWS_CODE(
+ KeysCollectionDocument::parse(IDLParserErrorContext("keyDoc"), serializedObj),
+ AssertionException,
+ 40414);
}
TEST(KeysCollectionDocument, MissingPurposeShouldFailToParse) {
@@ -92,13 +92,15 @@ TEST(KeysCollectionDocument, MissingPurposeShouldFailToParse) {
const auto expiresAt = LogicalTime(Timestamp(100, 200));
BSONObjBuilder builder;
- builder.append("keyId", keyId);
+ builder.append("_id", keyId);
builder.append("key", BSONBinData(key.data(), key.size(), BinDataGeneral));
expiresAt.asTimestamp().append(builder.bb(), "expiresAt");
auto serializedObj = builder.done();
- auto status = KeysCollectionDocument::fromBSON(serializedObj).getStatus();
- ASSERT_EQ(ErrorCodes::NoSuchKey, status);
+ ASSERT_THROWS_CODE(
+ KeysCollectionDocument::parse(IDLParserErrorContext("keyDoc"), serializedObj),
+ AssertionException,
+ 40414);
}
TEST(KeysCollectionDocument, MissingKeyShouldFailToParse) {
@@ -109,13 +111,15 @@ TEST(KeysCollectionDocument, MissingKeyShouldFailToParse) {
const auto expiresAt = LogicalTime(Timestamp(100, 200));
BSONObjBuilder builder;
- builder.append("keyId", keyId);
+ builder.append("_id", keyId);
builder.append("purpose", purpose);
expiresAt.asTimestamp().append(builder.bb(), "expiresAt");
auto serializedObj = builder.done();
- auto status = KeysCollectionDocument::fromBSON(serializedObj).getStatus();
- ASSERT_EQ(ErrorCodes::NoSuchKey, status);
+ ASSERT_THROWS_CODE(
+ KeysCollectionDocument::parse(IDLParserErrorContext("keyDoc"), serializedObj),
+ AssertionException,
+ 40414);
}
TEST(KeysCollectionDocument, MissingExpiresAtShouldFailToParse) {
@@ -128,13 +132,15 @@ TEST(KeysCollectionDocument, MissingExpiresAtShouldFailToParse) {
TimeProofService::Key key(keyHash);
BSONObjBuilder builder;
- builder.append("keyId", keyId);
+ builder.append("_id", keyId);
builder.append("purpose", purpose);
builder.append("key", BSONBinData(key.data(), key.size(), BinDataGeneral));
auto serializedObj = builder.done();
- auto status = KeysCollectionDocument::fromBSON(serializedObj).getStatus();
- ASSERT_EQ(ErrorCodes::NoSuchKey, status);
+ ASSERT_THROWS_CODE(
+ KeysCollectionDocument::parse(IDLParserErrorContext("keyDoc"), serializedObj),
+ AssertionException,
+ 40414);
}
} // namespace