Skip to content

Commit

Permalink
GODRIVER-2396 Add ChangeStreamPreAndPostImages to CreateCollectionOpt…
Browse files Browse the repository at this point in the history
…ions. (#941)
  • Loading branch information
benjirewis authored May 11, 2022
1 parent ed33f31 commit 189a713
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"description": "createCollection-pre_and_post_images",
"schemaVersion": "1.0",
"runOnRequirements": [
{
"minServerVersion": "6.0"
}
],
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "papi-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"tests": [
{
"description": "createCollection with changeStreamPreAndPostImages enabled",
"operations": [
{
"name": "dropCollection",
"object": "database0",
"arguments": {
"collection": "test"
}
},
{
"name": "createCollection",
"object": "database0",
"arguments": {
"collection": "test",
"changeStreamPreAndPostImages": {
"enabled": true
}
}
},
{
"name": "assertCollectionExists",
"object": "testRunner",
"arguments": {
"databaseName": "papi-tests",
"collectionName": "test"
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"drop": "test"
},
"databaseName": "papi-tests"
}
},
{
"commandStartedEvent": {
"command": {
"create": "test",
"changeStreamPreAndPostImages": {
"enabled": true
}
},
"databaseName": "papi-tests"
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
description: "createCollection-pre_and_post_images"

schemaVersion: "1.0"

runOnRequirements:
- minServerVersion: "6.0"

createEntities:
- client:
id: &client0 client0
observeEvents: [ commandStartedEvent ]
- database:
id: &database0 database0
client: *client0
databaseName: &database0Name papi-tests
- collection:
id: &collection0 collection0
database: *database0
collectionName: &collection0Name test

tests:
- description: "createCollection with changeStreamPreAndPostImages enabled"
operations:
- name: dropCollection
object: *database0
arguments:
collection: *collection0Name
- name: createCollection
object: *database0
arguments:
collection: *collection0Name
changeStreamPreAndPostImages: { enabled: true }
- name: assertCollectionExists
object: testRunner
arguments:
databaseName: *database0Name
collectionName: *collection0Name
expectEvents:
- client: *client0
events:
- commandStartedEvent:
command:
drop: *collection0Name
databaseName: *database0Name
- commandStartedEvent:
command:
create: *collection0Name
changeStreamPreAndPostImages: { enabled: true }
databaseName: *database0Name
110 changes: 110 additions & 0 deletions data/collection-management/modifyCollection-pre_and_post_images.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"description": "modifyCollection-pre_and_post_images",
"schemaVersion": "1.0",
"runOnRequirements": [
{
"minServerVersion": "6.0"
}
],
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "papi-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"tests": [
{
"description": "modifyCollection to changeStreamPreAndPostImages enabled",
"operations": [
{
"name": "dropCollection",
"object": "database0",
"arguments": {
"collection": "test"
}
},
{
"name": "createCollection",
"object": "database0",
"arguments": {
"collection": "test",
"changeStreamPreAndPostImages": {
"enabled": false
}
}
},
{
"name": "assertCollectionExists",
"object": "testRunner",
"arguments": {
"databaseName": "papi-tests",
"collectionName": "test"
}
},
{
"name": "modifyCollection",
"object": "database0",
"arguments": {
"collection": "test",
"changeStreamPreAndPostImages": {
"enabled": true
}
}
}
],
"expectEvents": [
{
"client": "client0",
"events": [
{
"commandStartedEvent": {
"command": {
"drop": "test"
},
"databaseName": "papi-tests"
}
},
{
"commandStartedEvent": {
"command": {
"create": "test",
"changeStreamPreAndPostImages": {
"enabled": false
}
}
}
},
{
"commandStartedEvent": {
"command": {
"collMod": "test",
"changeStreamPreAndPostImages": {
"enabled": true
}
}
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
description: "modifyCollection-pre_and_post_images"

schemaVersion: "1.0"

runOnRequirements:
- minServerVersion: "6.0"

createEntities:
- client:
id: &client0 client0
observeEvents: [ commandStartedEvent ]
- database:
id: &database0 database0
client: *client0
databaseName: &database0Name papi-tests
- collection:
id: &collection0 collection0
database: *database0
collectionName: &collection0Name test

tests:
- description: "modifyCollection to changeStreamPreAndPostImages enabled"
operations:
- name: dropCollection
object: *database0
arguments:
collection: *collection0Name
- name: createCollection
object: *database0
arguments:
collection: *collection0Name
changeStreamPreAndPostImages: { enabled: false }
- name: assertCollectionExists
object: testRunner
arguments:
databaseName: *database0Name
collectionName: *collection0Name
- name: modifyCollection
object: *database0
arguments:
collection: *collection0Name
changeStreamPreAndPostImages: { enabled: true }
expectEvents:
- client: *client0
events:
- commandStartedEvent:
command:
drop: *collection0Name
databaseName: *database0Name
- commandStartedEvent:
command:
create: *collection0Name
changeStreamPreAndPostImages: { enabled: false }
- commandStartedEvent:
command:
collMod: *collection0Name
changeStreamPreAndPostImages: { enabled: true }
7 changes: 7 additions & 0 deletions mongo/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ func (db *Database) CreateCollection(ctx context.Context, name string, opts ...*
if cco.Collation != nil {
op.Collation(bsoncore.Document(cco.Collation.ToDocument()))
}
if cco.ChangeStreamPreAndPostImages != nil {
csppi, err := transformBsoncoreDocument(db.registry, cco.ChangeStreamPreAndPostImages, true, "changeStreamPreAndPostImages")
if err != nil {
return err
}
op.ChangeStreamPreAndPostImages(csppi)
}
if cco.DefaultIndexOptions != nil {
idx, doc := bsoncore.AppendDocumentStart(nil)
if cco.DefaultIndexOptions.StorageEngine != nil {
Expand Down
17 changes: 13 additions & 4 deletions mongo/integration/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,10 @@ func TestDatabase(t *testing.T) {
// Tests for various options combinations. The test creates a collection with some options and then verifies
// the result using the options document reported by listCollections.

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

csppiOpts := options.CreateCollection().SetChangeStreamPreAndPostImages(bson.M{"enabled": true})
csppiExpected := bson.M{
"changeStreamPreAndPostImages": bson.M{
"enabled": true,
},
}

testCases := []struct {
name string
minServerVersion string
maxServerVersion string
createOpts *options.CreateCollectionOptions
expectedOpts bson.M
}{
{"all options except collation", "3.2", "", nonCollationOpts, nonCollationExpected},
{"all options except collation and csppi", "3.2", "", nonCollationOpts, nonCollationExpected},
{"changeStreamPreAndPostImages", "6.0", "", csppiOpts, csppiExpected},
}

for _, tc := range testCases {
Expand Down
2 changes: 2 additions & 0 deletions mongo/integration/unified/database_operation_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func executeCreateCollection(ctx context.Context, operation *operation) (*operat
switch key {
case "collection":
collName = val.StringValue()
case "changeStreamPreAndPostImages":
cco.SetChangeStreamPreAndPostImages(val.Document())
case "expireAfterSeconds":
cco.SetExpireAfterSeconds(int64(val.Int32()))
case "timeseries":
Expand Down
4 changes: 4 additions & 0 deletions mongo/integration/unified/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (op *operation) run(ctx context.Context, loopDone <-chan struct{}) (*operat
return executeIterateOnce(ctx, op)
case "iterateUntilDocumentOrError":
return executeIterateUntilDocumentOrError(ctx, op)

// Unsupported operations
case "count", "listIndexNames", "modifyCollection":
return nil, newSkipTestError(fmt.Sprintf("the %q operation is not supported", op.Name))
default:
return nil, fmt.Errorf("unrecognized entity operation %q", op.Name)
}
Expand Down
4 changes: 4 additions & 0 deletions mongo/integration/unified/unified_spec_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ func (tc *TestCase) Run(ls LoggerSkipper) error {

for idx, operation := range tc.Operations {
if err := operation.execute(testCtx, tc.loopDone); err != nil {
if isSkipTestError(err) {
ls.Skip(err)
}

return fmt.Errorf("error running operation %q at index %d: %v", operation.Name, idx, err)
}
}
Expand Down
Loading

0 comments on commit 189a713

Please sign in to comment.