Skip to content
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

Introduce Functional Options for MsSQL Connector #1089

Merged
merged 9 commits into from
Jan 16, 2020
Merged

Conversation

BradleyBoutcher
Copy link
Contributor

What does this PR do (include background context, if relevant)?

This PR is focused on improving the foundation of our current MsSQL tests, reducing code reuse and time needed to build new unit tests for the connector. It additionally includes a division between tests for our connector, and tests for our production options.

  • NewSingleUseConnectorWithOptions allows custom injection of dependencies without needing to specify all of them
  • ConnectorOptions struct captures all the configuration options for a SingleUseConnector
  • ConnectorOption is the 'functional option' complement to ConnectorOptions
  • Introduce tests that cover the 'production' options - dependencies we will use during production.
  • Covers each option specified in the singleuseconnector
  • Introduces mock options structure used for unit testing, including a function which returns default options
  • Unit tests now make use of the t.Run structure, where each test can be ran from within a single connect function
  • Introduces helper functions for testing around failure
  • Makes use of the new functional options feature in the connector

This is a re-uploaded PR of @doodlesbykumbi's work. All credit should go to him.

What ticket does this PR close?

Connected to:
#1010
#1073

Where should the reviewer start?

internal/plugin/connectors/tcp/mssql/connector_test.go

What is the status of the manual tests?

Have you run the following manual tests to verify existing functionality continues to function as expected?
NA

If this feature does not have any/sufficent automated tests, have you created/updated a folder in test/manual that includes:
NA

Links to open issues for related automated integration and unit tests

NA

Links to open issues for related documentation (in READMEs, docs, etc)

NA

Screenshots (if appropriate)

NA

Copy link
Contributor Author

@BradleyBoutcher BradleyBoutcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resubmitting comments from @diverdane

// ServerPreloginResponse => map[uint8][]byte{}
// ServerLoginResponse => &mssql.LoginResponse{}
// BackendConn => nil
// BackendConn => nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote @diverdane

Do we want to use 'options' here instead of 'setters', per Johah's previous comment, or is this used intentionally to distinguish this from ConnectorOptions?

internal/plugin/connectors/tcp/mssql/connector_test.go Outdated Show resolved Hide resolved
- NewSingleUseConnectorWithOptions allows custom injection of dependencies without needing to specify all of them
- ConnectorOptions struct captures all the configuration options for a SingleUseConnector
- ConnectorOption is the 'functional option' complement to ConnectorOptions
- Implemented
- Introduce tests that cover the 'production' options - dependencies we will use during production.
- Covers each option specified in the singleuseconnector
- Introduces mock options structure used for unit testing, including a function which returns default options
- Unit tests now make use of the t.Run structure, where each test can be ran from within a single connect function
- Introduces helper functions for testing around failure
- Makes use of the new functional options feature in the connector
@BradleyBoutcher BradleyBoutcher force-pushed the functional-options branch 2 times, most recently from 7bde982 to ccdac7e Compare January 15, 2020 21:04
SingleUseConnector now has types.ConnectorOptions
as an embedded type, allowing us to skip an
additional constructor method

NewSingleUseConnectorWithOptions has been moved
to the connector_test.go
NewSingleUseConnectorWithOptions is now package private
in connector_test.go

Ordered chronologically the tests in prod_options_test

Made DefaultConnectorOptions a variable in options.go
- WriteLogin Succeeds
- WriteLogin Fails

- ReadLogin Succeeds
- ReadLogin Fails
This change adds a test case for a failing readPrelogin call
- WritePreloginSucceeds test
  - The production version of WritePreloginWithPacketType
    succeeds when all others succeed
   - We receive the prelogin fields from the go-mssqldb driver
   - We modify the prelogin fields before sending them to the user

- WritePreloginFails test
  - Error is returned from connect
  - Error is written to client buffer
  - Error written to log
Copy link
Contributor Author

@BradleyBoutcher BradleyBoutcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@diverdane diverdane merged commit fe90e35 into master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants