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

feat: add module to support Microsoft SQL Server #1969

Merged
merged 16 commits into from Dec 6, 2023

Conversation

agosmou
Copy link
Contributor

@agosmou agosmou commented Dec 3, 2023

What does this PR do?

  • Adds the MSSQL module for quick bootstrapping on projects that require MS SQL Server in Docker for testing in. Scoffolding done following these instructions

Preface: MS SQL Server Docker Container

Minimum required environment variables to start a mssql container:

  • password
  • port
  • accept license agreement

MS SQL Server Docker image:

  • mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04 - source

Critical File Notes

  • modules/mssql.go

    • docker image default
      • const defaultImage = "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04"
    • The Microsoft SQL Server default Systems Administrator account username is "sa." This MUST be used in the connection string, as it is the default user on creation, so it can be 'hard-entered' into the connection string, but I set it as a constant for clarity.
      • defaultUsername = "sa" // default microsoft system administrator
    • Microsoft requires the users accepts an End User Licensing Agreement (EULA) so this is done manually by the user using the method:
      • func WithAcceptEULA( )
    • Microsoft has a password 'minimum strength' policy for their containers. I set the password as a constant for user convenience, but they are able to set their own password if they wish with the method:
      • func WithPassword(password string)
    • The connection string method takes variadic parameters following the convention from Microsoft's mssql module
      • sqlserver://username:password@host:port?param1=value&param2=value
  • modules/mssql_test.go

    • Standard Test
      • TestMSSQLServer
    • EULA Option Validation
      • Microsoft requires the user accepta the EULA. source. Failure to accept, by omitting the WithAcceptEula() method, will not allow the container to be created
        • TestMSSQLServerWithMissingEulaOption
    • Connection String Test
      • TestMSSQLServerWithConnectionStringParameters
        • e.g. connectionString, err := container.ConnectionString(ctx, "encrypt=false", "TrustServerCertificate=true")
    • Password Validation Tests: confirms Microsoft's docker image service handles their password validation
      • proper
        • TestMSSQLServerWithCustomStrongPassword
      • improper
        • TestMSSQLServerWithInvalidPassword
    • Substituting Image Test
      • TestMSSQLServerWithAlternativeImage
        • e.g. mcr.microsoft.com/mssql/server:2019-latest
  • modules/examples_test.go

    • Typical End-User Example: tests typical container example demonstrating the acceptance of the EULA and adding a custom password.
      • ExampleRunContainer()
  • docs/modules/mssql.md

    • EULA warning is highlighted on the documentation page as seen here
    • The connection string method takes variadic parameters and is demonstrated on the bottom of the page

Why is it important?

  • To better facilitate testing with Microsoft SQL Server in docker with Go using the testcontainers-go library

Related issues

Copy link

netlify bot commented Dec 3, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 639d26c
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/657023a52a615e0008683025
😎 Deploy Preview https://deploy-preview-1969--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

docs/modules/mssql.md Show resolved Hide resolved
modules/mssql/mssql.go Show resolved Hide resolved
modules/mssql/mssql.go Show resolved Hide resolved
modules/mssql/mssql.go Outdated Show resolved Hide resolved
modules/mssql/mssql_test.go Show resolved Hide resolved
modules/mssql/mssql.go Show resolved Hide resolved
@agosmou agosmou marked this pull request as ready for review December 3, 2023 09:44
@agosmou agosmou requested a review from a team as a code owner December 3, 2023 09:44
modules/mssql/mssql.go Outdated Show resolved Hide resolved
@mdelapenya mdelapenya self-assigned this Dec 5, 2023
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Dec 5, 2023
@agosmou
Copy link
Contributor Author

agosmou commented Dec 5, 2023

@mdelapenya

I made some minor changes after I saw the linting failed. It should be all set now - minor cleanup on tests.

db4662d

modules/mssql/mssql.go Outdated Show resolved Hide resolved
@agosmou
Copy link
Contributor Author

agosmou commented Dec 6, 2023

@mdelapenya

latest commit e70e482

  • adjust docker image to a fixed, stable version in lieu of the 'latest'
  • moves docker image constant into the constant block
  • adds documentation for WithAcceptEULA and WithPassword

mdelapenya
mdelapenya previously approved these changes Dec 6, 2023
Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM! I suggested the fix for the double-spaced lines, so I'll commit them and merge this PR.

Thanks for your time working in this cool module! Much appreciated!

PS: because the module catalog project is in a private repo, I'll submit it asap and it will appear there really soon.

docs/modules/mssql.md Outdated Show resolved Hide resolved
docs/modules/mssql.md Outdated Show resolved Hide resolved
@mdelapenya
Copy link
Collaborator

BTW, I did not mention before, but excellent job with the PR description 👏 Really glad I can read it and drive the review from there.
image

* main:
  chore(deps): bump github.com/shirou/gopsutil/v3 from 3.23.10 to 3.23.11 (testcontainers#1943)
@mdelapenya mdelapenya merged commit 0d24f17 into testcontainers:main Dec 6, 2023
116 checks passed
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Dec 12, 2023
* main: (24 commits)
  chore(deps): bump github.com/ClickHouse/clickhouse-go/v2 (testcontainers#1982)
  chore(deps): bump github.com/twmb/franz-go in /modules/redpanda (testcontainers#1973)
  chore(deps): bump google.golang.org/api from 0.152.0 to 0.153.0, cloud.google.com/go/bigtable from 1.20.0 to 1.21.0 and cloud.google.com/go/spanner from 1.53.0 to 1.53.1 in /modules/gcloud (testcontainers#1983)
  chore(deps): bump github.com/aws/aws-sdk-go and github.com/aws/aws-sdk-go-v2 in /modules/localstack (testcontainers#1981)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.0.1 to 6.0.4 (testcontainers#1974)
  feat: add module to support Microsoft SQL Server (testcontainers#1969)
  chore(deps): bump github.com/shirou/gopsutil/v3 from 3.23.10 to 3.23.11 (testcontainers#1943)
  chore(deps): bump golang.org/x/mod in /modules/kafka (testcontainers#1956)
  chore(deps): bump golang.org/x/sys from 0.13.0 to 0.15.0 (testcontainers#1944)
  chore(deps): bump golang.org/x/text and golang.org/x/mod from 0.13.0 to 0.14.0 in /modulegen (testcontainers#1968)
  chore(deps): bump go.mongodb.org/mongo-driver in /modules/mongodb (testcontainers#1960)
  chore(deps): bump github.com/couchbase/gocb/v2 in /modules/couchbase (testcontainers#1952)
  chore(deps): bump github.com/elastic/go-elasticsearch/v8 from 8.10.1 to 8.11.1 and golang.org/x/mod from 0.13.0 to 0.14.0 in /modules/elasticsearch (testcontainers#1967)
  chore(deps): bump github.com/aws/aws-sdk-go and github.com/aws/aws-sdk-go-v2 in /modules/localstack (testcontainers#1953)
  chore(deps): bump actions/github-script from 6.4.1 to 7.0.1 (testcontainers#1949)
  chore(deps): bump github.com/IBM/sarama in /modules/kafka (testcontainers#1955)
  chore(deps): bump github.com/neo4j/neo4j-go-driver/v5 in /modules/neo4j (testcontainers#1961)
  chore(deps): bump github.com/compose-spec/compose-go from 1.20.0 to 1.20.2 and github.com/docker/compose/v2 from 2.23.0 to 2.23.3 in /modules/compose (testcontainers#1966)
  chore(deps): bump google.golang.org/api from 0.143.0 to 0.152.0 and cloud.google.com/go/spanner from 1.50.0 to 1.53.0 in /modules/gcloud (testcontainers#1965)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.0.1 to 6.0.4 (testcontainers#1934)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add MSSQLServer module
2 participants