Skip to content

Commit

Permalink
Merge pull request #714 from eaze/josh/test-sqlserver-with-edge
Browse files Browse the repository at this point in the history
Run SQL server tests on Azure SQL Edge
  • Loading branch information
dhui committed Mar 17, 2022
2 parents 57aead3 + 9d3babd commit cc5f8b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
42 changes: 36 additions & 6 deletions database/sqlserver/sqlserver_test.go
Expand Up @@ -6,11 +6,13 @@ import (
sqldriver "database/sql/driver"
"fmt"
"log"
"runtime"
"strings"
"testing"
"time"

"github.com/dhui/dktest"
"github.com/docker/go-connections/nat"
"github.com/golang-migrate/migrate/v4"

dt "github.com/golang-migrate/migrate/v4/database/testing"
Expand All @@ -23,14 +25,27 @@ const defaultPort = 1433
const saPassword = "Root1234"

var (
opts = dktest.Options{
Env: map[string]string{"ACCEPT_EULA": "Y", "SA_PASSWORD": saPassword, "MSSQL_PID": "Express"},
sqlEdgeOpts = dktest.Options{
Env: map[string]string{"ACCEPT_EULA": "Y", "MSSQL_SA_PASSWORD": saPassword},
PortBindings: map[nat.Port][]nat.PortBinding{
nat.Port(fmt.Sprintf("%d/tcp", defaultPort)): {
nat.PortBinding{
HostIP: "0.0.0.0",
HostPort: "0/tcp",
},
},
},
PortRequired: true, ReadyFunc: isReady, PullTimeout: 2 * time.Minute,
}
sqlServerOpts = dktest.Options{
Env: map[string]string{"ACCEPT_EULA": "Y", "MSSQL_SA_PASSWORD": saPassword, "MSSQL_PID": "Express"},
PortRequired: true, ReadyFunc: isReady, PullTimeout: 2 * time.Minute,
}
// Container versions: https://mcr.microsoft.com/v2/mssql/server/tags/list
specs = []dktesting.ContainerSpec{
{ImageName: "mcr.microsoft.com/mssql/server:2017-latest", Options: opts},
{ImageName: "mcr.microsoft.com/mssql/server:2019-latest", Options: opts},
{ImageName: "mcr.microsoft.com/azure-sql-edge:latest", Options: sqlEdgeOpts},
{ImageName: "mcr.microsoft.com/mssql/server:2017-latest", Options: sqlServerOpts},
{ImageName: "mcr.microsoft.com/mssql/server:2019-latest", Options: sqlServerOpts},
}
)

Expand Down Expand Up @@ -74,8 +89,15 @@ func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
return true
}

func SkipIfUnsupportedArch(t *testing.T, c dktest.ContainerInfo) {
if strings.Contains(c.ImageName, "mssql") && !strings.HasPrefix(runtime.GOARCH, "amd") {
t.Skip(fmt.Sprintf("Image %s is not supported on arch %s", c.ImageName, runtime.GOARCH))
}
}

func Test(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
Expand All @@ -100,6 +122,7 @@ func Test(t *testing.T) {

func TestMigrate(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -128,7 +151,8 @@ func TestMigrate(t *testing.T) {

func TestMultiStatement(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
ip, port, err := c.FirstPort()
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -161,12 +185,14 @@ func TestMultiStatement(t *testing.T) {

func TestErrorParsing(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
ip, port, err := c.FirstPort()
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
}

addr := msConnectionString(ip, port)

p := &SQLServer{}
d, err := p.Open(addr)
if err != nil {
Expand All @@ -191,6 +217,7 @@ func TestErrorParsing(t *testing.T) {

func TestLockWorks(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -229,6 +256,7 @@ func TestLockWorks(t *testing.T) {

func TestMsiTrue(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
Expand All @@ -245,6 +273,7 @@ func TestMsiTrue(t *testing.T) {

func TestOpenWithPasswordAndMSI(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -276,6 +305,7 @@ func TestOpenWithPasswordAndMSI(t *testing.T) {

func TestMsiFalse(t *testing.T) {
dktesting.ParallelTest(t, specs, func(t *testing.T, c dktest.ContainerInfo) {
SkipIfUnsupportedArch(t, c)
ip, port, err := c.Port(defaultPort)
if err != nil {
t.Fatal(err)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -18,6 +18,7 @@ require (
github.com/denisenkom/go-mssqldb v0.10.0
github.com/dhui/dktest v0.3.9
github.com/docker/docker v20.10.12+incompatible
github.com/docker/go-connections v0.4.0 // indirect
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
github.com/envoyproxy/go-control-plane v0.10.1 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.2 // indirect
Expand Down

0 comments on commit cc5f8b7

Please sign in to comment.