Skip to content

Commit 55e2258

Browse files
test: add deadline for mysql container
1 parent 844b00a commit 55e2258

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/stretchr/testify v1.10.0
1515
github.com/swaggo/echo-swagger v1.4.1
1616
github.com/swaggo/swag v1.16.4
17+
github.com/testcontainers/testcontainers-go v0.37.0
1718
github.com/testcontainers/testcontainers-go/modules/mysql v0.37.0
1819
golang.org/x/crypto v0.38.0
1920
gorm.io/driver/mysql v1.5.2
@@ -248,7 +249,6 @@ require (
248249
github.com/subosito/gotenv v1.4.1 // indirect
249250
github.com/swaggo/files/v2 v2.0.0 // indirect
250251
github.com/tdakkota/asciicheck v0.4.0 // indirect
251-
github.com/testcontainers/testcontainers-go v0.37.0 // indirect
252252
github.com/tetafro/godot v1.4.20 // indirect
253253
github.com/timakin/bodyclose v0.0.0-20241017074812-ed6a65f985e3 // indirect
254254
github.com/timonwong/loggercheck v0.10.1 // indirect

tests/integration/post_repository_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ func TestPostRepository(t *testing.T) {
2323
err := gormDB.Create(userToCreate).Error
2424
require.NoError(t, err)
2525

26-
user := new(models.User)
27-
userRepository.GetUserByEmail(user, "example_user_email@email.com")
26+
user, err := userRepository.GetUserByEmail("example_user_email@email.com")
2827
require.NotNil(t, user)
2928

3029
postToCreate := &models.Post{
@@ -42,7 +41,7 @@ func TestPostRepository(t *testing.T) {
4241

4342
gotPost := (*gotPosts)[0]
4443
wantPost := postToCreate
45-
wantPost.User = *user
44+
wantPost.User = user
4645
wantPost.CreatedAt = gotPost.CreatedAt
4746
wantPost.UpdatedAt = gotPost.UpdatedAt
4847

tests/setup/mysql.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"time"
78

9+
"github.com/testcontainers/testcontainers-go"
810
"github.com/testcontainers/testcontainers-go/modules/mysql"
11+
"github.com/testcontainers/testcontainers-go/wait"
912
)
1013

1114
const (
@@ -33,6 +36,13 @@ func SetupMySQL(ctx context.Context) (_ MySQLConfig, _ func(ctx context.Context)
3336
mysql.WithDatabase(mysqlDatabase),
3437
mysql.WithUsername(mysqlUsername),
3538
mysql.WithPassword(mysqlPassword),
39+
testcontainers.WithWaitStrategyAndDeadline(
40+
time.Minute,
41+
wait.ForLog(fmt.Sprintf(
42+
"/usr/sbin/mysqld: ready for connections. Version: '9.3.0' socket: '/var/run/mysqld/mysqld.sock' port: %s MySQL Community Server - GPL.",
43+
mysqlPort,
44+
)),
45+
),
3646
)
3747
if err != nil {
3848
return MySQLConfig{}, nil, fmt.Errorf("run mysql container: %w", err)

0 commit comments

Comments
 (0)