-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from go-co-op/35-bug-mysql-doesnt-treat-null-a…
…s-a-valid-default-for-not-null-fields Fixing bug with mysql and default null value for not null columns
- Loading branch information
Showing
4 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package gormlock | ||
|
||
import ( | ||
"context" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/testcontainers/testcontainers-go" | ||
"github.com/testcontainers/testcontainers-go/modules/mysql" | ||
gormMysql "gorm.io/driver/mysql" | ||
"gorm.io/gorm" | ||
"testing" | ||
) | ||
|
||
func TestAutoMigration_MySQL(t *testing.T) { | ||
t.Parallel() | ||
tests := map[string]struct { | ||
img string | ||
args []string | ||
}{ | ||
"8.0.36": { | ||
img: "mysql:8.0.36", | ||
args: []string{"charset=utf8mb4", "parseTime=True", "loc=Local"}, | ||
}, | ||
} | ||
|
||
for name, tc := range tests { | ||
name, tc := name, tc | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
mysqlContainer, err := mysql.Run(ctx, | ||
tc.img, | ||
mysql.WithDatabase("test"), | ||
mysql.WithUsername("root"), | ||
mysql.WithPassword("password"), | ||
) | ||
require.NoError(t, err, "failed to start container") | ||
defer func() { | ||
if err := testcontainers.TerminateContainer(mysqlContainer); err != nil { | ||
t.Fatalf("failed to terminate container: %s", err) | ||
} | ||
}() | ||
|
||
connStr, errConn := mysqlContainer.ConnectionString(ctx, tc.args...) | ||
require.NoError(t, errConn, "failed to get mysql connection string") | ||
|
||
db, errOpeningConn := gorm.Open(gormMysql.Open(connStr), &gorm.Config{}) | ||
require.NoError(t, errOpeningConn) | ||
|
||
err = db.AutoMigrate(&CronJobLock{}) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |