@@ -6,11 +6,13 @@ import (
6
6
sqldriver "database/sql/driver"
7
7
"fmt"
8
8
"log"
9
+ "runtime"
9
10
"strings"
10
11
"testing"
11
12
"time"
12
13
13
14
"github.com/dhui/dktest"
15
+ "github.com/docker/go-connections/nat"
14
16
"github.com/golang-migrate/migrate/v4"
15
17
16
18
dt "github.com/golang-migrate/migrate/v4/database/testing"
@@ -23,14 +25,27 @@ const defaultPort = 1433
23
25
const saPassword = "Root1234"
24
26
25
27
var (
26
- opts = dktest.Options {
27
- Env : map [string ]string {"ACCEPT_EULA" : "Y" , "SA_PASSWORD" : saPassword , "MSSQL_PID" : "Express" },
28
+ sqlEdgeOpts = dktest.Options {
29
+ Env : map [string ]string {"ACCEPT_EULA" : "Y" , "MSSQL_SA_PASSWORD" : saPassword },
30
+ PortBindings : map [nat.Port ][]nat.PortBinding {
31
+ nat .Port (fmt .Sprintf ("%d/tcp" , defaultPort )): {
32
+ nat.PortBinding {
33
+ HostIP : "0.0.0.0" ,
34
+ HostPort : "0/tcp" ,
35
+ },
36
+ },
37
+ },
38
+ PortRequired : true , ReadyFunc : isReady , PullTimeout : 2 * time .Minute ,
39
+ }
40
+ sqlServerOpts = dktest.Options {
41
+ Env : map [string ]string {"ACCEPT_EULA" : "Y" , "MSSQL_SA_PASSWORD" : saPassword , "MSSQL_PID" : "Express" },
28
42
PortRequired : true , ReadyFunc : isReady , PullTimeout : 2 * time .Minute ,
29
43
}
30
44
// Container versions: https://mcr.microsoft.com/v2/mssql/server/tags/list
31
45
specs = []dktesting.ContainerSpec {
32
- {ImageName : "mcr.microsoft.com/mssql/server:2017-latest" , Options : opts },
33
- {ImageName : "mcr.microsoft.com/mssql/server:2019-latest" , Options : opts },
46
+ {ImageName : "mcr.microsoft.com/azure-sql-edge:latest" , Options : sqlEdgeOpts },
47
+ {ImageName : "mcr.microsoft.com/mssql/server:2017-latest" , Options : sqlServerOpts },
48
+ {ImageName : "mcr.microsoft.com/mssql/server:2019-latest" , Options : sqlServerOpts },
34
49
}
35
50
)
36
51
@@ -74,8 +89,15 @@ func isReady(ctx context.Context, c dktest.ContainerInfo) bool {
74
89
return true
75
90
}
76
91
92
+ func SkipIfUnsupportedArch (t * testing.T , c dktest.ContainerInfo ) {
93
+ if strings .Contains (c .ImageName , "mssql" ) && ! strings .HasPrefix (runtime .GOARCH , "amd" ) {
94
+ t .Skip (fmt .Sprintf ("Image %s is not supported on arch %s" , c .ImageName , runtime .GOARCH ))
95
+ }
96
+ }
97
+
77
98
func Test (t * testing.T ) {
78
99
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
100
+ SkipIfUnsupportedArch (t , c )
79
101
ip , port , err := c .Port (defaultPort )
80
102
if err != nil {
81
103
t .Fatal (err )
@@ -100,6 +122,7 @@ func Test(t *testing.T) {
100
122
101
123
func TestMigrate (t * testing.T ) {
102
124
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
125
+ SkipIfUnsupportedArch (t , c )
103
126
ip , port , err := c .Port (defaultPort )
104
127
if err != nil {
105
128
t .Fatal (err )
@@ -128,7 +151,8 @@ func TestMigrate(t *testing.T) {
128
151
129
152
func TestMultiStatement (t * testing.T ) {
130
153
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
131
- ip , port , err := c .FirstPort ()
154
+ SkipIfUnsupportedArch (t , c )
155
+ ip , port , err := c .Port (defaultPort )
132
156
if err != nil {
133
157
t .Fatal (err )
134
158
}
@@ -161,12 +185,14 @@ func TestMultiStatement(t *testing.T) {
161
185
162
186
func TestErrorParsing (t * testing.T ) {
163
187
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
164
- ip , port , err := c .FirstPort ()
188
+ SkipIfUnsupportedArch (t , c )
189
+ ip , port , err := c .Port (defaultPort )
165
190
if err != nil {
166
191
t .Fatal (err )
167
192
}
168
193
169
194
addr := msConnectionString (ip , port )
195
+
170
196
p := & SQLServer {}
171
197
d , err := p .Open (addr )
172
198
if err != nil {
@@ -191,6 +217,7 @@ func TestErrorParsing(t *testing.T) {
191
217
192
218
func TestLockWorks (t * testing.T ) {
193
219
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
220
+ SkipIfUnsupportedArch (t , c )
194
221
ip , port , err := c .Port (defaultPort )
195
222
if err != nil {
196
223
t .Fatal (err )
@@ -229,6 +256,7 @@ func TestLockWorks(t *testing.T) {
229
256
230
257
func TestMsiTrue (t * testing.T ) {
231
258
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
259
+ SkipIfUnsupportedArch (t , c )
232
260
ip , port , err := c .Port (defaultPort )
233
261
if err != nil {
234
262
t .Fatal (err )
@@ -245,6 +273,7 @@ func TestMsiTrue(t *testing.T) {
245
273
246
274
func TestOpenWithPasswordAndMSI (t * testing.T ) {
247
275
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
276
+ SkipIfUnsupportedArch (t , c )
248
277
ip , port , err := c .Port (defaultPort )
249
278
if err != nil {
250
279
t .Fatal (err )
@@ -276,6 +305,7 @@ func TestOpenWithPasswordAndMSI(t *testing.T) {
276
305
277
306
func TestMsiFalse (t * testing.T ) {
278
307
dktesting .ParallelTest (t , specs , func (t * testing.T , c dktest.ContainerInfo ) {
308
+ SkipIfUnsupportedArch (t , c )
279
309
ip , port , err := c .Port (defaultPort )
280
310
if err != nil {
281
311
t .Fatal (err )
0 commit comments