Skip to content

Commit 189a713

Browse files
authored
GODRIVER-2396 Add ChangeStreamPreAndPostImages to CreateCollectionOptions. (#941)
1 parent ed33f31 commit 189a713

11 files changed

+390
-27
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"description": "createCollection-pre_and_post_images",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "6.0"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0",
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "papi-tests"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "test"
30+
}
31+
}
32+
],
33+
"tests": [
34+
{
35+
"description": "createCollection with changeStreamPreAndPostImages enabled",
36+
"operations": [
37+
{
38+
"name": "dropCollection",
39+
"object": "database0",
40+
"arguments": {
41+
"collection": "test"
42+
}
43+
},
44+
{
45+
"name": "createCollection",
46+
"object": "database0",
47+
"arguments": {
48+
"collection": "test",
49+
"changeStreamPreAndPostImages": {
50+
"enabled": true
51+
}
52+
}
53+
},
54+
{
55+
"name": "assertCollectionExists",
56+
"object": "testRunner",
57+
"arguments": {
58+
"databaseName": "papi-tests",
59+
"collectionName": "test"
60+
}
61+
}
62+
],
63+
"expectEvents": [
64+
{
65+
"client": "client0",
66+
"events": [
67+
{
68+
"commandStartedEvent": {
69+
"command": {
70+
"drop": "test"
71+
},
72+
"databaseName": "papi-tests"
73+
}
74+
},
75+
{
76+
"commandStartedEvent": {
77+
"command": {
78+
"create": "test",
79+
"changeStreamPreAndPostImages": {
80+
"enabled": true
81+
}
82+
},
83+
"databaseName": "papi-tests"
84+
}
85+
}
86+
]
87+
}
88+
]
89+
}
90+
]
91+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
description: "createCollection-pre_and_post_images"
2+
3+
schemaVersion: "1.0"
4+
5+
runOnRequirements:
6+
- minServerVersion: "6.0"
7+
8+
createEntities:
9+
- client:
10+
id: &client0 client0
11+
observeEvents: [ commandStartedEvent ]
12+
- database:
13+
id: &database0 database0
14+
client: *client0
15+
databaseName: &database0Name papi-tests
16+
- collection:
17+
id: &collection0 collection0
18+
database: *database0
19+
collectionName: &collection0Name test
20+
21+
tests:
22+
- description: "createCollection with changeStreamPreAndPostImages enabled"
23+
operations:
24+
- name: dropCollection
25+
object: *database0
26+
arguments:
27+
collection: *collection0Name
28+
- name: createCollection
29+
object: *database0
30+
arguments:
31+
collection: *collection0Name
32+
changeStreamPreAndPostImages: { enabled: true }
33+
- name: assertCollectionExists
34+
object: testRunner
35+
arguments:
36+
databaseName: *database0Name
37+
collectionName: *collection0Name
38+
expectEvents:
39+
- client: *client0
40+
events:
41+
- commandStartedEvent:
42+
command:
43+
drop: *collection0Name
44+
databaseName: *database0Name
45+
- commandStartedEvent:
46+
command:
47+
create: *collection0Name
48+
changeStreamPreAndPostImages: { enabled: true }
49+
databaseName: *database0Name
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"description": "modifyCollection-pre_and_post_images",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "6.0"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0",
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "papi-tests"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "test"
30+
}
31+
}
32+
],
33+
"tests": [
34+
{
35+
"description": "modifyCollection to changeStreamPreAndPostImages enabled",
36+
"operations": [
37+
{
38+
"name": "dropCollection",
39+
"object": "database0",
40+
"arguments": {
41+
"collection": "test"
42+
}
43+
},
44+
{
45+
"name": "createCollection",
46+
"object": "database0",
47+
"arguments": {
48+
"collection": "test",
49+
"changeStreamPreAndPostImages": {
50+
"enabled": false
51+
}
52+
}
53+
},
54+
{
55+
"name": "assertCollectionExists",
56+
"object": "testRunner",
57+
"arguments": {
58+
"databaseName": "papi-tests",
59+
"collectionName": "test"
60+
}
61+
},
62+
{
63+
"name": "modifyCollection",
64+
"object": "database0",
65+
"arguments": {
66+
"collection": "test",
67+
"changeStreamPreAndPostImages": {
68+
"enabled": true
69+
}
70+
}
71+
}
72+
],
73+
"expectEvents": [
74+
{
75+
"client": "client0",
76+
"events": [
77+
{
78+
"commandStartedEvent": {
79+
"command": {
80+
"drop": "test"
81+
},
82+
"databaseName": "papi-tests"
83+
}
84+
},
85+
{
86+
"commandStartedEvent": {
87+
"command": {
88+
"create": "test",
89+
"changeStreamPreAndPostImages": {
90+
"enabled": false
91+
}
92+
}
93+
}
94+
},
95+
{
96+
"commandStartedEvent": {
97+
"command": {
98+
"collMod": "test",
99+
"changeStreamPreAndPostImages": {
100+
"enabled": true
101+
}
102+
}
103+
}
104+
}
105+
]
106+
}
107+
]
108+
}
109+
]
110+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
description: "modifyCollection-pre_and_post_images"
2+
3+
schemaVersion: "1.0"
4+
5+
runOnRequirements:
6+
- minServerVersion: "6.0"
7+
8+
createEntities:
9+
- client:
10+
id: &client0 client0
11+
observeEvents: [ commandStartedEvent ]
12+
- database:
13+
id: &database0 database0
14+
client: *client0
15+
databaseName: &database0Name papi-tests
16+
- collection:
17+
id: &collection0 collection0
18+
database: *database0
19+
collectionName: &collection0Name test
20+
21+
tests:
22+
- description: "modifyCollection to changeStreamPreAndPostImages enabled"
23+
operations:
24+
- name: dropCollection
25+
object: *database0
26+
arguments:
27+
collection: *collection0Name
28+
- name: createCollection
29+
object: *database0
30+
arguments:
31+
collection: *collection0Name
32+
changeStreamPreAndPostImages: { enabled: false }
33+
- name: assertCollectionExists
34+
object: testRunner
35+
arguments:
36+
databaseName: *database0Name
37+
collectionName: *collection0Name
38+
- name: modifyCollection
39+
object: *database0
40+
arguments:
41+
collection: *collection0Name
42+
changeStreamPreAndPostImages: { enabled: true }
43+
expectEvents:
44+
- client: *client0
45+
events:
46+
- commandStartedEvent:
47+
command:
48+
drop: *collection0Name
49+
databaseName: *database0Name
50+
- commandStartedEvent:
51+
command:
52+
create: *collection0Name
53+
changeStreamPreAndPostImages: { enabled: false }
54+
- commandStartedEvent:
55+
command:
56+
collMod: *collection0Name
57+
changeStreamPreAndPostImages: { enabled: true }

mongo/database.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,13 @@ func (db *Database) CreateCollection(ctx context.Context, name string, opts ...*
516516
if cco.Collation != nil {
517517
op.Collation(bsoncore.Document(cco.Collation.ToDocument()))
518518
}
519+
if cco.ChangeStreamPreAndPostImages != nil {
520+
csppi, err := transformBsoncoreDocument(db.registry, cco.ChangeStreamPreAndPostImages, true, "changeStreamPreAndPostImages")
521+
if err != nil {
522+
return err
523+
}
524+
op.ChangeStreamPreAndPostImages(csppi)
525+
}
519526
if cco.DefaultIndexOptions != nil {
520527
idx, doc := bsoncore.AppendDocumentStart(nil)
521528
if cco.DefaultIndexOptions.StorageEngine != nil {

mongo/integration/database_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,10 @@ func TestDatabase(t *testing.T) {
432432
// Tests for various options combinations. The test creates a collection with some options and then verifies
433433
// the result using the options document reported by listCollections.
434434

435-
// All possible options except collation. The collation is omitted here and tested below because the
436-
// collation document reported by listCollections fills in extra fields and includes a "version" field
437-
// that's not described in https://www.mongodb.com/docs/manual/reference/collation/.
435+
// All possible options except collation and changeStreamPreAndPostImages. The collation is omitted here and tested below because the
436+
// collation document reported by listCollections fills in extra fields and includes a "version" field that's not described in
437+
// https://www.mongodb.com/docs/manual/reference/collation/. changeStreamPreAndPostImages is omitted here and tested in another testcase
438+
// because it is only an available option on 6.0+.
438439
storageEngine := bson.M{
439440
"wiredTiger": bson.M{
440441
"configString": "block_compressor=zlib",
@@ -473,14 +474,22 @@ func TestDatabase(t *testing.T) {
473474
"validationLevel": "moderate",
474475
}
475476

477+
csppiOpts := options.CreateCollection().SetChangeStreamPreAndPostImages(bson.M{"enabled": true})
478+
csppiExpected := bson.M{
479+
"changeStreamPreAndPostImages": bson.M{
480+
"enabled": true,
481+
},
482+
}
483+
476484
testCases := []struct {
477485
name string
478486
minServerVersion string
479487
maxServerVersion string
480488
createOpts *options.CreateCollectionOptions
481489
expectedOpts bson.M
482490
}{
483-
{"all options except collation", "3.2", "", nonCollationOpts, nonCollationExpected},
491+
{"all options except collation and csppi", "3.2", "", nonCollationOpts, nonCollationExpected},
492+
{"changeStreamPreAndPostImages", "6.0", "", csppiOpts, csppiExpected},
484493
}
485494

486495
for _, tc := range testCases {

mongo/integration/unified/database_operation_execution.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func executeCreateCollection(ctx context.Context, operation *operation) (*operat
3333
switch key {
3434
case "collection":
3535
collName = val.StringValue()
36+
case "changeStreamPreAndPostImages":
37+
cco.SetChangeStreamPreAndPostImages(val.Document())
3638
case "expireAfterSeconds":
3739
cco.SetExpireAfterSeconds(int64(val.Int32()))
3840
case "timeseries":

mongo/integration/unified/operation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ func (op *operation) run(ctx context.Context, loopDone <-chan struct{}) (*operat
155155
return executeIterateOnce(ctx, op)
156156
case "iterateUntilDocumentOrError":
157157
return executeIterateUntilDocumentOrError(ctx, op)
158+
159+
// Unsupported operations
160+
case "count", "listIndexNames", "modifyCollection":
161+
return nil, newSkipTestError(fmt.Sprintf("the %q operation is not supported", op.Name))
158162
default:
159163
return nil, fmt.Errorf("unrecognized entity operation %q", op.Name)
160164
}

mongo/integration/unified/unified_spec_runner.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ func (tc *TestCase) Run(ls LoggerSkipper) error {
272272

273273
for idx, operation := range tc.Operations {
274274
if err := operation.execute(testCtx, tc.loopDone); err != nil {
275+
if isSkipTestError(err) {
276+
ls.Skip(err)
277+
}
278+
275279
return fmt.Errorf("error running operation %q at index %d: %v", operation.Name, idx, err)
276280
}
277281
}

0 commit comments

Comments
 (0)