Skip to content

Commit c1933ed

Browse files
authored
Merge pull request #1515 from mdelapenya/tc-go-adoption-2
chore: adopt testcontainers-go for Postgres, MySQL and MongoDB
2 parents 715cafd + 1137981 commit c1933ed

29 files changed

+1277
-298
lines changed

.github/workflows/benchmark.yml

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -81,46 +81,6 @@ jobs:
8181
run: |
8282
docker run -d -p 11211:11211 memcached:latest
8383
84-
- name: Install MongoDB
85-
if: ${{ matrix.package == 'mongodb' }}
86-
run: |
87-
docker run -d -p 27017:27017 mongo:latest
88-
89-
- name: Install MSSQL
90-
if: ${{ matrix.package == 'mssql' }}
91-
run: |
92-
docker run -d -p 1433:1433 \
93-
-e "ACCEPT_EULA=Y" -e "SA_PASSWORD=MsSql!1234" \
94-
-e "MSSQL_DB=master" -e "MSSQL_USER=sa" \
95-
-e "MSSQL_PASSWORD=MsSql!1234" \
96-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD -Q 'select 1' -b -o /dev/null" \
97-
--health-interval 1s \
98-
--health-timeout 30s \
99-
--health-start-period 10s \
100-
--health-retries 20 \
101-
mcmoe/mssqldocker:latest
102-
103-
- name: Install MySQL
104-
if: ${{ matrix.package == 'mysql' }}
105-
run: |
106-
docker run -d -p 3306:3306 \
107-
-e "MYSQL_DATABASE=fiber" \
108-
-e "MYSQL_USER=username" \
109-
-e "MYSQL_PASSWORD=password" \
110-
-e "MYSQL_ROOT_PASSWORD=password" \
111-
--health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5 \
112-
mysql:latest
113-
114-
- name: Install Postgres
115-
if: ${{ matrix.package == 'postgres' }}
116-
run: |
117-
docker run -d -p 5432:5432 \
118-
-e "POSTGRES_DB=fiber" \
119-
-e "POSTGRES_USER=username" \
120-
-e "POSTGRES_PASSWORD=pass#w%rd" \
121-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 \
122-
postgres:latest
123-
12484
- name: Install Azurite
12585
if: ${{ matrix.package == 'azureblob' }}
12686
run: |
@@ -179,21 +139,18 @@ jobs:
179139
run: |
180140
set -o pipefail
181141
echo "Bench dir: ${{ matrix.package }}"
182-
go test ./... -benchmem -run=^$ -bench . | tee -a output.txt
142+
go test ./... -timeout 900s -benchmem -run=^$ -bench . | tee -a output.txt
183143
shell: bash
184144
env:
185145
MSSQL_DATABASE: master
186146
MSSQL_USERNAME: sa
187147
MSSQL_PASSWORD: MsSql!1234
188-
MYSQL_USERNAME: username
189-
MYSQL_PASSWORD: password
190-
MYSQL_DATABASE: fiber
191-
POSTGRES_DATABASE: fiber
192-
POSTGRES_USERNAME: username
193-
POSTGRES_PASSWORD: "pass#w%rd"
194148
TEST_CLICKHOUSE_IMAGE: "clickhouse/clickhouse-server:23-alpine"
195-
TEST_COUCHBASE_IMAGE: "couchbase:enterprise-7.1.1"
149+
TEST_COUCHBASE_IMAGE: "couchbase:enterprise-7.6.5"
196150
TEST_MINIO_IMAGE: "docker.io/minio/minio:RELEASE.2024-08-17T01-24-54Z"
151+
TEST_MONGODB_IMAGE: "docker.io/mongo:7"
152+
TEST_MYSQL_IMAGE: "docker.io/mysql:9"
153+
TEST_POSTGRES_IMAGE: "docker.io/postgres:16-alpine"
197154

198155
- name: Get Previous Benchmark Results
199156
uses: actions/cache@v4

.github/workflows/test-clickhouse.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ jobs:
1515
strategy:
1616
matrix:
1717
go-version:
18-
- 1.21.x
1918
- 1.22.x
19+
- 1.23.x
20+
- 1.24.x
2021
steps:
2122
- name: Fetch Repository
2223
uses: actions/checkout@v4

.github/workflows/test-couchbase.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
strategy:
1616
matrix:
1717
go-version:
18-
- 1.21.x
1918
- 1.22.x
2019
- 1.23.x
20+
- 1.24.x
2121
steps:
2222
- name: Fetch Repository
2323
uses: actions/checkout@v4
@@ -27,5 +27,5 @@ jobs:
2727
go-version: '${{ matrix.go-version }}'
2828
- name: Run Test
2929
env:
30-
TEST_COUCHBASE_IMAGE: couchbase:enterprise-7.1.1
30+
TEST_COUCHBASE_IMAGE: couchbase:enterprise-7.6.5
3131
run: cd ./couchbase && go test ./... -v -race

.github/workflows/test-minio.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
strategy:
1616
matrix:
1717
go-version:
18-
- 1.21.x
1918
- 1.22.x
2019
- 1.23.x
20+
- 1.24.x
2121
steps:
2222
- name: Fetch Repository
2323
uses: actions/checkout@v4

.github/workflows/test-mongodb.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@ name: "Tests Mongodb"
1212
jobs:
1313
Tests:
1414
runs-on: ubuntu-latest
15-
services:
16-
mongo:
17-
image: 'mongo:latest'
18-
ports:
19-
- '27017:27017'
2015
strategy:
2116
matrix:
2217
go-version:
23-
- 1.19.x
24-
- 1.20.x
25-
- 1.21.x
18+
- 1.22.x
19+
- 1.23.x
20+
- 1.24.x
2621
steps:
2722
- name: Fetch Repository
2823
uses: actions/checkout@v4
@@ -31,5 +26,7 @@ jobs:
3126
with:
3227
go-version: '${{ matrix.go-version }}'
3328
- name: Run Test
29+
env:
30+
TEST_MONGODB_IMAGE: docker.io/mongo:7
3431
run: cd ./mongodb && go test ./... -v -race
3532

.github/workflows/test-mysql.yml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,12 @@ name: "Tests MySQL"
1212
jobs:
1313
Tests:
1414
runs-on: ubuntu-latest
15-
services:
16-
mysql:
17-
image: 'mysql:latest'
18-
env:
19-
MYSQL_DATABASE: fiber
20-
MYSQL_USER: username
21-
MYSQL_PASSWORD: password
22-
MYSQL_ROOT_PASSWORD: password
23-
ports:
24-
- '3306:3306'
25-
options: >-
26-
--health-cmd "mysqladmin ping" --health-interval 10s --health-timeout
27-
5s --health-retries 5
2815
strategy:
2916
matrix:
3017
go-version:
31-
- 1.19.x
32-
- 1.20.x
33-
- 1.21.x
18+
- 1.22.x
19+
- 1.23.x
20+
- 1.24.x
3421
steps:
3522
- name: Fetch Repository
3623
uses: actions/checkout@v4
@@ -39,8 +26,6 @@ jobs:
3926
with:
4027
go-version: '${{ matrix.go-version }}'
4128
- name: Run Test
42-
run: cd ./mysql && go test ./... -v -race
4329
env:
44-
MYSQL_USERNAME: username
45-
MYSQL_PASSWORD: password
46-
MYSQL_DATABASE: fiber
30+
TEST_MYSQL_IMAGE: docker.io/mysql:9
31+
run: cd ./mysql && go test ./... -v -race

.github/workflows/test-postgres.yml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,12 @@ name: "Tests Postgres"
1212
jobs:
1313
Tests:
1414
runs-on: ubuntu-latest
15-
services:
16-
postgres:
17-
image: 'postgres:latest'
18-
ports:
19-
- '5432:5432'
20-
env:
21-
POSTGRES_DB: fiber
22-
POSTGRES_USER: username
23-
POSTGRES_PASSWORD: "pass#w%rd"
24-
options: >-
25-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
26-
--health-retries 5
2715
strategy:
2816
matrix:
2917
go-version:
30-
- 1.20.x
31-
- 1.21.x
3218
- 1.22.x
19+
- 1.23.x
20+
- 1.24.x
3321
steps:
3422
- name: Fetch Repository
3523
uses: actions/checkout@v4
@@ -38,8 +26,6 @@ jobs:
3826
with:
3927
go-version: '${{ matrix.go-version }}'
4028
- name: Run Test
41-
run: cd ./postgres && go test ./... -v -race
4229
env:
43-
POSTGRES_DATABASE: fiber
44-
POSTGRES_USERNAME: username
45-
POSTGRES_PASSWORD: "pass#w%rd"
30+
TEST_POSTGRES_IMAGE: "docker.io/postgres:16-alpine"
31+
run: cd ./postgres && go test ./... -v -race

clickhouse/clickhouse_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313

14+
"github.com/testcontainers/testcontainers-go"
1415
"github.com/testcontainers/testcontainers-go/modules/clickhouse"
16+
"github.com/testcontainers/testcontainers-go/wait"
1517
)
1618

1719
const (
@@ -21,6 +23,8 @@ const (
2123
clickhouseUser string = "default"
2224
clickhousePass string = "password"
2325
clickhouseDB string = "fiber"
26+
clickhouseHttpPort = "8123/tcp"
27+
clickhouseSuccessCode = 200
2428
)
2529

2630
func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
@@ -38,7 +42,16 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
3842
clickhouse.WithUsername(clickhouseUser),
3943
clickhouse.WithPassword(clickhousePass),
4044
clickhouse.WithDatabase(clickhouseDB),
45+
testcontainers.WithWaitStrategy(
46+
wait.ForAll(
47+
wait.ForListeningPort(clickhouseHttpPort),
48+
wait.NewHTTPStrategy("/").WithPort(clickhouseHttpPort).WithStatusCodeMatcher(func(status int) bool {
49+
return status == clickhouseSuccessCode
50+
}),
51+
),
52+
),
4153
)
54+
testcontainers.CleanupContainer(t, c)
4255
if err != nil {
4356
return nil, err
4457
}
@@ -67,13 +80,14 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
6780
}
6881

6982
func Test_Connection(t *testing.T) {
70-
_, err := getTestConnection(t, Config{
83+
client, err := getTestConnection(t, Config{
7184
Engine: Memory,
7285
Table: "test_table",
7386
Clean: true,
7487
})
75-
7688
require.NoError(t, err)
89+
90+
defer client.Close()
7791
}
7892

7993
func Test_Set(t *testing.T) {
@@ -191,6 +205,17 @@ func Test_Reset(t *testing.T) {
191205
assert.Equal(t, []byte{}, value)
192206
}
193207

208+
func TestClose_ShouldReturn_NoError(t *testing.T) {
209+
client, err := getTestConnection(t, Config{
210+
Engine: Memory,
211+
Table: "test_table",
212+
Clean: true,
213+
})
214+
require.NoError(t, err)
215+
216+
require.NoError(t, client.Close())
217+
}
218+
194219
func Benchmark_Clickhouse_Set(b *testing.B) {
195220
b.ReportAllocs()
196221
b.ResetTimer()

clickhouse/go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module github.com/gofiber/storage/clickhouse
22

3-
go 1.21
3+
go 1.22
44

55
require (
66
github.com/ClickHouse/clickhouse-go/v2 v2.26.0
77
github.com/stretchr/testify v1.9.0
8-
github.com/testcontainers/testcontainers-go/modules/clickhouse v0.33.0
8+
github.com/testcontainers/testcontainers-go v0.35.0
9+
github.com/testcontainers/testcontainers-go/modules/clickhouse v0.35.0
910
)
1011

1112
require (
@@ -18,7 +19,7 @@ require (
1819
github.com/containerd/containerd v1.7.18 // indirect
1920
github.com/containerd/log v0.1.0 // indirect
2021
github.com/containerd/platforms v0.2.1 // indirect
21-
github.com/cpuguy83/dockercfg v0.3.1 // indirect
22+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
2223
github.com/davecgh/go-spew v1.1.1 // indirect
2324
github.com/distribution/reference v0.6.0 // indirect
2425
github.com/docker/docker v27.1.1+incompatible // indirect
@@ -53,15 +54,14 @@ require (
5354
github.com/shoenig/go-m1cpu v0.1.6 // indirect
5455
github.com/shopspring/decimal v1.4.0 // indirect
5556
github.com/sirupsen/logrus v1.9.3 // indirect
56-
github.com/testcontainers/testcontainers-go v0.33.0 // indirect
5757
github.com/tklauser/go-sysconf v0.3.12 // indirect
5858
github.com/tklauser/numcpus v0.6.1 // indirect
5959
github.com/yusufpapurcu/wmi v1.2.3 // indirect
6060
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
6161
go.opentelemetry.io/otel v1.28.0 // indirect
6262
go.opentelemetry.io/otel/metric v1.28.0 // indirect
6363
go.opentelemetry.io/otel/trace v1.28.0 // indirect
64-
golang.org/x/crypto v0.24.0 // indirect
65-
golang.org/x/sys v0.21.0 // indirect
64+
golang.org/x/crypto v0.31.0 // indirect
65+
golang.org/x/sys v0.28.0 // indirect
6666
gopkg.in/yaml.v3 v3.0.1 // indirect
6767
)

0 commit comments

Comments
 (0)