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
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ updates:
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/mssql
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
- package-ecosystem: gomod
directory: /modules/mysql
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
matrix:
go-version: [1.20.x, 1.x]
platform: [ubuntu-latest, macos-latest]
module: [artemis, cassandra, clickhouse, compose, couchbase, elasticsearch, gcloud, k3s, k6, kafka, localstack, mariadb, mongodb, mysql, nats, neo4j, postgres, pulsar, rabbitmq, redis, redpanda, vault]
module: [artemis, cassandra, clickhouse, compose, couchbase, elasticsearch, gcloud, k3s, k6, kafka, localstack, mariadb, mongodb, mssql, mysql, nats, neo4j, postgres, pulsar, rabbitmq, redis, redpanda, vault]
exclude:
- go-version: 1.20.x
module: compose
Expand Down
4 changes: 4 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
"name": "module / mongodb",
"path": "../modules/mongodb"
},
{
"name": "module / mssql",
"path": "../modules/mssql"
},
{
"name": "module / mysql",
"path": "../modules/mysql"
Expand Down
63 changes: 63 additions & 0 deletions docs/modules/mssql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# MS SQL Server

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for MSSQLServer.

## Adding this module to your project dependencies

Please run the following command to add the MSSQLServer module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/mssql
```

## Usage example

<!--codeinclude-->
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved

mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
[Creating a MSSQLServer container](../../modules/mssql/examples_test.go) inside_block:runMSSQLServerContainer

mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
<!--/codeinclude-->

!!! warning "EULA Acceptance"
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
Due to licensing restrictions you are required to accept an End User License Agreement (EULA) for this container image. To indicate that you accept the MS SQL Server image EULA, call the `WithAcceptEULA("Y")` method passing a "yes" parameter as `"Y"` to indicate EULA acceptance.

Please see the [`microsoft-mssql-server` image documentation](https://hub.docker.com/_/microsoft-mssql-server#environment-variables) for a link to the EULA document.

## Module reference

The MSSQLServer module exposes one entrypoint function to create the MSSQLServer container, and this function receives two parameters:

```golang
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MSSQLServerContainer, error)
```

- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the MSSQLServer container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different MSSQLServer Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for MSSQLServer. E.g. `testcontainers.WithImage("mcr.microsoft.com/mssql/server:2022-latest")`.

mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
{% include "../features/common_functional_options.md" %}

### Container Methods

The MSSQLServer container exposes the following methods:

#### ConnectionString

This method returns the connection string to connect to the Microsoft SQL Server container, using the default `1433` port.
It's possible to pass extra parameters to the connection string, e.g. `encrypt=false` or `TrustServerCertificate=true`, in a variadic way.

```golang
connectionString, err := container.ConnectionString(ctx, "encrypt=false", "TrustServerCertificate=true")
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ nav:
- modules/localstack.md
- modules/mariadb.md
- modules/mongodb.md
- modules/mssql.md
- modules/mysql.md
- modules/nats.md
- modules/neo4j.md
Expand Down
5 changes: 5 additions & 0 deletions modules/mssql/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-mssql
44 changes: 44 additions & 0 deletions modules/mssql/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package mssql_test

import (
"context"
"fmt"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/mssql"
)

func ExampleRunContainer() {
// runMSSQLServerContainer {
ctx := context.Background()

acceptEula := "Y"
password := "Strong@Passw0rd"

mssqlContainer, err := mssql.RunContainer(ctx,
testcontainers.WithImage("mcr.microsoft.com/mssql/server:2022-latest"),
mssql.WithAcceptEULA(acceptEula),
mssql.WithPassword(password),
)
if err != nil {
panic(err)
}

// Clean up the container
defer func() {
if err := mssqlContainer.Terminate(ctx); err != nil {
panic(err)
}
}()
// }

state, err := mssqlContainer.State(ctx)
if err != nil {
panic(err)
}

fmt.Println(state.Running)

// Output:
// true
}
63 changes: 63 additions & 0 deletions modules/mssql/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module github.com/testcontainers/testcontainers-go/modules/mssql

go 1.20

require (
github.com/microsoft/go-mssqldb v1.6.0
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.26.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.7 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.10 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/testcontainers/testcontainers-go => ../..