Skip to content

Commit ef6e278

Browse files
CDRIVER-2917 support new test operations for change stream json tests
1 parent 8ae6d32 commit ef6e278

File tree

2 files changed

+289
-0
lines changed

2 files changed

+289
-0
lines changed

src/libmongoc/tests/json-test-operations.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,56 @@ insert_many (mongoc_collection_t *collection,
10201020
}
10211021

10221022

1023+
static void
1024+
rename_op (mongoc_collection_t *collection,
1025+
const bson_t *test,
1026+
const bson_t *operation,
1027+
mongoc_client_session_t *session,
1028+
mongoc_write_concern_t *wc)
1029+
{
1030+
bson_t args;
1031+
bson_t result;
1032+
const char *db;
1033+
const char *to;
1034+
bson_error_t error;
1035+
bool res;
1036+
1037+
bson_lookup_doc (operation, "arguments", &args);
1038+
db = bson_lookup_utf8 (operation, "database");
1039+
to = bson_lookup_utf8 (&args, "to");
1040+
1041+
res = mongoc_collection_rename (collection, db, to, true, &error);
1042+
1043+
/* This operation is only run by change stream tests, which use
1044+
it to trigger further events and check all results elsewhere. */
1045+
ASSERT_OR_PRINT (res, error);
1046+
1047+
bson_destroy (&args);
1048+
bson_destroy (&result);
1049+
}
1050+
1051+
1052+
static void
1053+
drop (mongoc_collection_t *collection,
1054+
const bson_t *test,
1055+
const bson_t *operation,
1056+
mongoc_client_session_t *session,
1057+
mongoc_write_concern_t *wc)
1058+
{
1059+
bson_t result;
1060+
bson_error_t error;
1061+
bool res;
1062+
1063+
res = mongoc_collection_drop (collection, &error);
1064+
1065+
/* This operation is only run by change stream tests, which use
1066+
it to trigger further events and check all results elsewhere. */
1067+
ASSERT_OR_PRINT (res, error);
1068+
1069+
bson_destroy (&result);
1070+
}
1071+
1072+
10231073
static void
10241074
count (mongoc_collection_t *collection,
10251075
const bson_t *test,
@@ -1464,6 +1514,10 @@ json_test_operation (json_test_ctx_t *ctx,
14641514
find_and_modify (c, test, operation, session, wc);
14651515
} else if (!strcmp (op_name, "insertMany")) {
14661516
insert_many (c, test, operation, session, wc);
1517+
} else if (!strcmp (op_name, "rename")) {
1518+
rename_op (c, test, operation, session, wc);
1519+
} else if (!strcmp (op_name, "drop")) {
1520+
drop (c, test, operation, session, wc);
14671521
} else if (!strcmp (op_name, "count")) {
14681522
count (c, test, operation, session, read_prefs);
14691523
} else if (!strcmp (op_name, "estimatedDocumentCount")) {

src/libmongoc/tests/json/change_streams/change-streams.json

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,241 @@
440440
}
441441
]
442442
}
443+
},
444+
{
445+
"description": "Test insert, update, replace, and delete event types",
446+
"minServerVersion": "3.6.0",
447+
"target": "collection",
448+
"topology": [
449+
"replicaset"
450+
],
451+
"changeStreamPipeline": [],
452+
"changeStreamOptions": {},
453+
"operations": [
454+
{
455+
"database": "change-stream-tests",
456+
"collection": "test",
457+
"name": "insertOne",
458+
"arguments": {
459+
"document": {
460+
"x": 1
461+
}
462+
}
463+
},
464+
{
465+
"database": "change-stream-tests",
466+
"collection": "test",
467+
"name": "updateOne",
468+
"arguments": {
469+
"filter": {
470+
"x": 1
471+
},
472+
"update": {
473+
"$set": {
474+
"x": 2
475+
}
476+
}
477+
}
478+
},
479+
{
480+
"database": "change-stream-tests",
481+
"collection": "test",
482+
"name": "replaceOne",
483+
"arguments": {
484+
"filter": {
485+
"x": 2
486+
},
487+
"replacement": {
488+
"x": 3
489+
}
490+
}
491+
},
492+
{
493+
"database": "change-stream-tests",
494+
"collection": "test",
495+
"name": "deleteOne",
496+
"arguments": {
497+
"filter": {
498+
"x": 3
499+
}
500+
}
501+
}
502+
],
503+
"expectations": [
504+
{
505+
"command_started_event": {
506+
"command": {
507+
"aggregate": "test",
508+
"cursor": {},
509+
"pipeline": [
510+
{
511+
"$changeStream": {
512+
"fullDocument": "default"
513+
}
514+
}
515+
]
516+
},
517+
"command_name": "aggregate",
518+
"database_name": "change-stream-tests"
519+
}
520+
}
521+
],
522+
"result": {
523+
"success": [
524+
{
525+
"operationType": "insert",
526+
"ns": {
527+
"db": "change-stream-tests",
528+
"coll": "test"
529+
},
530+
"fullDocument": {
531+
"x": {
532+
"$numberInt": "1"
533+
}
534+
}
535+
},
536+
{
537+
"operationType": "update",
538+
"ns": {
539+
"db": "change-stream-tests",
540+
"coll": "test"
541+
},
542+
"updateDescription": {
543+
"updatedFields": {
544+
"x": {
545+
"$numberInt": "2"
546+
}
547+
}
548+
}
549+
},
550+
{
551+
"operationType": "replace",
552+
"ns": {
553+
"db": "change-stream-tests",
554+
"coll": "test"
555+
},
556+
"fullDocument": {
557+
"x": {
558+
"$numberInt": "3"
559+
}
560+
}
561+
},
562+
{
563+
"operationType": "delete",
564+
"ns": {
565+
"db": "change-stream-tests",
566+
"coll": "test"
567+
}
568+
}
569+
]
570+
}
571+
},
572+
{
573+
"description": "Test rename and invalidate event types",
574+
"minServerVersion": "4.0.1",
575+
"target": "collection",
576+
"topology": [
577+
"replicaset"
578+
],
579+
"changeStreamPipeline": [],
580+
"changeStreamOptions": {},
581+
"operations": [
582+
{
583+
"database": "change-stream-tests",
584+
"collection": "test",
585+
"name": "rename",
586+
"arguments": {
587+
"to": "test2"
588+
}
589+
}
590+
],
591+
"expectations": [
592+
{
593+
"command_started_event": {
594+
"command": {
595+
"aggregate": "test",
596+
"cursor": {},
597+
"pipeline": [
598+
{
599+
"$changeStream": {
600+
"fullDocument": "default"
601+
}
602+
}
603+
]
604+
},
605+
"command_name": "aggregate",
606+
"database_name": "change-stream-tests"
607+
}
608+
}
609+
],
610+
"result": {
611+
"success": [
612+
{
613+
"operationType": "rename",
614+
"ns": {
615+
"db": "change-stream-tests",
616+
"coll": "test"
617+
},
618+
"to": {
619+
"db": "change-stream-tests",
620+
"coll": "test2"
621+
}
622+
},
623+
{
624+
"operationType": "invalidate"
625+
}
626+
]
627+
}
628+
},
629+
{
630+
"description": "Test drop and invalidate event types",
631+
"minServerVersion": "4.0.1",
632+
"target": "collection",
633+
"topology": [
634+
"replicaset"
635+
],
636+
"changeStreamPipeline": [],
637+
"changeStreamOptions": {},
638+
"operations": [
639+
{
640+
"database": "change-stream-tests",
641+
"collection": "test",
642+
"name": "drop"
643+
}
644+
],
645+
"expectations": [
646+
{
647+
"command_started_event": {
648+
"command": {
649+
"aggregate": "test",
650+
"cursor": {},
651+
"pipeline": [
652+
{
653+
"$changeStream": {
654+
"fullDocument": "default"
655+
}
656+
}
657+
]
658+
},
659+
"command_name": "aggregate",
660+
"database_name": "change-stream-tests"
661+
}
662+
}
663+
],
664+
"result": {
665+
"success": [
666+
{
667+
"operationType": "drop",
668+
"ns": {
669+
"db": "change-stream-tests",
670+
"coll": "test"
671+
}
672+
},
673+
{
674+
"operationType": "invalidate"
675+
}
676+
]
677+
}
443678
}
444679
]
445680
}

0 commit comments

Comments
 (0)