Skip to content

Commit

Permalink
M1 Mac Support for Testing
Browse files Browse the repository at this point in the history
The library/mysql container doesn't support arm64/v8,
which caused the tests to not be runnable on M1 Macs.

This commit adds two ways to solve this:

1. TestDB now has a SkippedArchs property, which
allows certain Docker containers to be tagged to
not support certain runtime.GOARCH strings. These
cause a skipped test when used.
2. The MySQL test container was switched from
libary/mysql to mysql/mysql-server (the one produced
directly by the MySQL team), which *does* support
arm64/v8, but only on the latest MySQL 8 version.
  • Loading branch information
adlio committed Mar 25, 2022
1 parent 531e542 commit cfb349d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"runtime"
"sync"
"testing"

Expand Down Expand Up @@ -33,7 +34,9 @@ func TestMain(m *testing.M) {
testDB := TestDBs[name]
wg.Add(1)
go func() {
testDB.Init(pool)
if testDB.IsRunnable() {
testDB.Init(pool)
}
wg.Done()
}()
}
Expand Down Expand Up @@ -66,7 +69,11 @@ func withEachDialect(t *testing.T, f func(t *testing.T, d Dialect)) {
func withEachTestDB(t *testing.T, f func(t *testing.T, tdb *TestDB)) {
for dbName, tdb := range TestDBs {
t.Run(dbName, func(t *testing.T) {
f(t, tdb)
if tdb.IsRunnable() {
f(t, tdb)
} else {
t.Skipf("Not runnable on %s", runtime.GOARCH)
}
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var TestDBs map[string]*TestDB = map[string]*TestDB{
"mysql:latest": {
Dialect: MySQL,
Driver: MySQLDriverName,
DockerRepo: "mysql",
DockerRepo: "mysql/mysql-server",
DockerTag: "latest",
},
"mariadb:latest": {
Expand Down
23 changes: 17 additions & 6 deletions testdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"os"
"runtime"
"testing"

"github.com/ory/dockertest"
Expand All @@ -16,12 +17,13 @@ import (
// to run database migration tests.
//
type TestDB struct {
Dialect Dialect
Driver string
DockerRepo string
DockerTag string
Resource *dockertest.Resource
path string
Dialect Dialect
Driver string
DockerRepo string
DockerTag string
Resource *dockertest.Resource
SkippedArchs []string
path string
}

func (c *TestDB) Username() string {
Expand Down Expand Up @@ -80,6 +82,15 @@ func (c *TestDB) DockerEnvars() []string {
}
}

func (c *TestDB) IsRunnable() bool {
for _, skippedArch := range c.SkippedArchs {
if skippedArch == runtime.GOARCH {
return false
}
}
return true
}

// Path computes the full path to the database on disk (applies only to SQLite
// instances).
func (c *TestDB) Path() string {
Expand Down

0 comments on commit cfb349d

Please sign in to comment.