-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3241 Move mock OPMSG deployment to the experimental package #1831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
API Change Report./v2/x/mongo/driver/drivertestcompatible changesMockDeployment: added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this ticket is to move the deployment to the experimental package, and use it where needed internally. Allowing external users to mock a server, if they want. See here for a rough POC of the proposal: prestonvasquez@dd57d5b
) | ||
|
||
func TestOPMSGMockDeployment(t *testing.T) { | ||
var md *MockDeployment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept the unit test as a mock without actually connecting because the process of connecting with a mock deployment confused me, but if it would be better coverage to actually connect would definitely appreciate guidance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test this using a client. For example:
md := NewMockDeployment()
opts := options.Client()
opts.Opts = append(opts.Opts, func(co *options.ClientOptions) error {
co.Deployment = md
return nil
})
client, err := mongo.Connect(opts)
require.NoError(t, err)
md.AddResponses(bson.D{{"ok", 1}})
err = client.Ping(context.Background(), nil)
require.NoError(t, err)
) | ||
|
||
func TestOPMSGMockDeployment(t *testing.T) { | ||
var md *MockDeployment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test this using a client. For example:
md := NewMockDeployment()
opts := options.Client()
opts.Opts = append(opts.Opts, func(co *options.ClientOptions) error {
co.Deployment = md
return nil
})
client, err := mongo.Connect(opts)
require.NoError(t, err)
md.AddResponses(bson.D{{"ok", 1}})
err = client.Ping(context.Background(), nil)
require.NoError(t, err)
func newMockDeployment(responses ...bson.D) *mockDeployment { | ||
return &mockDeployment{ | ||
// NewMockDeployment returns a mock driver.Deployment that responds with OP_MSG wire messages. | ||
func NewMockDeployment(responses ...bson.D) *MockDeployment { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joyjwang We should note in the comment that for most use cases it's better to test with an actual database.
CC: @matthewdale
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appologies for the inconvenience, but could we move opmsg_deploymeng.go and the test to x/mongo/driver/drivertest/? That's where the mock connection API lives, and seems more suitable than x/mongo/driver/integration.
GODRIVER-3241
Summary
Background & Motivation