Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adopt testcontainers-go for Postgres, MySQL, MSSQL and MongoDB #1515

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4ed3649
chore: use testcontainers-go in mongodb store
mdelapenya Aug 29, 2024
0e060e1
chore: use testcontainers-go in mssql store
mdelapenya Aug 29, 2024
2f17493
chore: use testcontainers-go in mysql store
mdelapenya Aug 29, 2024
2f5263e
chore: use testcontainers-go in postgres store
mdelapenya Aug 29, 2024
689759c
fix: wrong image name for mongo
mdelapenya Aug 29, 2024
ff25433
fix: proper Go version matrix
mdelapenya Aug 29, 2024
fc01fc5
fix: remove toolchain in go mod
mdelapenya Aug 29, 2024
4ad4b03
chor: consistent Go version
mdelapenya Aug 29, 2024
b53f02b
fix: remove toolchain
mdelapenya Aug 29, 2024
de8f798
chore: consistent Go versions matrix
mdelapenya Aug 29, 2024
471a6ac
fix: remove more postgres options
mdelapenya Sep 16, 2024
c80f126
chore: adjust Go matrix versions to use 1.20 as the minimum version
mdelapenya Sep 16, 2024
1d6c0c3
chore: set Go 1.21 for modules
mdelapenya Sep 16, 2024
4d7a172
chore: use Ubuntu 22.04 base image for MSSQL
mdelapenya Sep 18, 2024
75c8525
chore: close store for previous modules
mdelapenya Sep 18, 2024
1bb4d92
chore: close store
mdelapenya Sep 18, 2024
f962d64
chore: terminate container on end
mdelapenya Sep 18, 2024
1c23d53
chore: bump MSSQL image to not crash in the GH workers
mdelapenya Sep 19, 2024
7bbad9a
fix: swap values in mysql constants
mdelapenya Sep 19, 2024
efbc89f
fix: do not close store twice in tests
mdelapenya Sep 19, 2024
153c837
fix: reorder
mdelapenya Sep 19, 2024
43a47ef
fix: do not close twice in mysql test
mdelapenya Sep 19, 2024
3cd89db
fix: terminate second mysql container
mdelapenya Sep 19, 2024
60be628
chore: bump couchbase image
mdelapenya Sep 19, 2024
a4849c8
Revert "fix: terminate second mysql container"
mdelapenya Sep 19, 2024
b3a2e40
chore: bump testcontainers-go to v0.34.0
mdelapenya Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 4 additions & 52 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,6 @@ jobs:
image: 'memcached:latest'
ports:
- '11211:11211'
mongo:
image: 'mongo:latest'
ports:
- '27017:27017'
mssql:
image: 'mcmoe/mssqldocker:latest'
ports:
- '1433:1433'
env:
ACCEPT_EULA: Y
SA_PASSWORD: MsSql!1234
MSSQL_DB: master
MSSQL_USER: sa
MSSQL_PASSWORD: MsSql!1234
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD -Q 'select 1' -b -o /dev/null"
--health-interval 1s
--health-timeout 30s
--health-start-period 10s
--health-retries 20
mysql:
image: 'mysql:latest'
env:
MYSQL_DATABASE: fiber
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- '3306:3306'
options: >-
--health-cmd "mysqladmin ping" --health-interval 10s --health-timeout
5s --health-retries 5
postgres:
image: 'postgres:latest'
ports:
- '5432:5432'
env:
POSTGRES_DB: fiber
POSTGRES_USER: username
POSTGRES_PASSWORD: "pass#w%rd"
options: >-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
--health-retries 5

steps:
- name: Fetch Repository
Expand Down Expand Up @@ -152,18 +109,13 @@ jobs:
done
shell: bash
env:
MSSQL_DATABASE: master
MSSQL_USERNAME: sa
MSSQL_PASSWORD: MsSql!1234
MYSQL_USERNAME: username
MYSQL_PASSWORD: password
MYSQL_DATABASE: fiber
POSTGRES_DATABASE: fiber
POSTGRES_USERNAME: username
POSTGRES_PASSWORD: "pass#w%rd"
TEST_CLICKHOUSE_IMAGE: "clickhouse/clickhouse-server:23-alpine"
TEST_COUCHBASE_IMAGE: "couchbase:enterprise-7.1.1"
TEST_MINIO_IMAGE: "docker.io/minio/minio:RELEASE.2024-08-17T01-24-54Z"
TEST_MONGODB_IMAGE: "docker.io/mongo:7"
TEST_MSSQL_IMAGE: "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04"
TEST_MYSQL_IMAGE: "docker.io/mysql:9"
TEST_POSTGRES_IMAGE: "docker.io/postgres:16-alpine"

- name: Get Previous Benchmark Results
uses: actions/cache@v4
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/test-mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ name: "Tests Mongodb"
jobs:
Tests:
runs-on: ubuntu-latest
services:
mongo:
image: 'mongo:latest'
ports:
- '27017:27017'
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.22.x
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand All @@ -31,5 +26,7 @@ jobs:
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
env:
TEST_MONGODB_IMAGE: docker.io/mongo:7
run: cd ./mongodb && go test ./... -v -race

25 changes: 3 additions & 22 deletions .github/workflows/test-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,12 @@ name: "Tests MSSQL"
jobs:
Tests:
runs-on: ubuntu-latest
services:
mssql:
image: 'mcmoe/mssqldocker:latest'
ports:
- '1433:1433'
env:
ACCEPT_EULA: Y
SA_PASSWORD: MsSql!1234
MSSQL_DB: master
MSSQL_USER: sa
MSSQL_PASSWORD: MsSql!1234
options: >-
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD -Q 'select 1' -b -o /dev/null"
--health-interval 1s
--health-timeout 30s
--health-start-period 10s
--health-retries 20
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.22.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand All @@ -43,8 +26,6 @@ jobs:
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
run: cd ./mssql && go test ./... -v -race
env:
MSSQL_DATABASE: master
MSSQL_USERNAME: sa
MSSQL_PASSWORD: MsSql!1234
TEST_MSSQL_IMAGE: "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04"
run: cd ./mssql && go test ./... -v -race
21 changes: 3 additions & 18 deletions .github/workflows/test-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,12 @@ name: "Tests MySQL"
jobs:
Tests:
runs-on: ubuntu-latest
services:
mysql:
image: 'mysql:latest'
env:
MYSQL_DATABASE: fiber
MYSQL_USER: username
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- '3306:3306'
options: >-
--health-cmd "mysqladmin ping" --health-interval 10s --health-timeout
5s --health-retries 5
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.22.x
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand All @@ -39,8 +26,6 @@ jobs:
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
run: cd ./mysql && go test ./... -v -race
env:
MYSQL_USERNAME: username
MYSQL_PASSWORD: password
MYSQL_DATABASE: fiber
TEST_MYSQL_IMAGE: docker.io/mysql:9
run: cd ./mysql && go test ./... -v -race
18 changes: 2 additions & 16 deletions .github/workflows/test-postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ name: "Tests Postgres"
jobs:
Tests:
runs-on: ubuntu-latest
services:
postgres:
image: 'postgres:latest'
ports:
- '5432:5432'
env:
POSTGRES_DB: fiber
POSTGRES_USER: username
POSTGRES_PASSWORD: "pass#w%rd"
options: >-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
--health-retries 5
strategy:
matrix:
go-version:
Expand All @@ -38,8 +26,6 @@ jobs:
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
run: cd ./postgres && go test ./... -v -race
env:
POSTGRES_DATABASE: fiber
POSTGRES_USERNAME: username
POSTGRES_PASSWORD: "pass#w%rd"
TEST_POSTGRES_IMAGE: "docker.io/postgres:16-alpine"
run: cd ./postgres && go test ./... -v -race
8 changes: 7 additions & 1 deletion clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
if err != nil {
return nil, err
}
t.Cleanup(func() {
if c != nil {
require.NoError(t, c.Terminate(ctx))
}
})

hostPort, err := c.ConnectionHost(ctx)
if err != nil {
Expand All @@ -67,11 +72,12 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) {
}

func Test_Connection(t *testing.T) {
_, err := getTestConnection(t, Config{
client, err := getTestConnection(t, Config{
Engine: Memory,
Table: "test_table",
Clean: true,
})
defer client.Close()

require.NoError(t, err)
}
Expand Down
16 changes: 16 additions & 0 deletions couchbase/couchbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func newTestStore(t testing.TB) (*Storage, error) {
if err != nil {
return nil, err
}
t.Cleanup(func() {
if c != nil {
require.NoError(t, c.Terminate(ctx))
}
})

conn, err := c.ConnectionString(ctx)
if err != nil {
Expand All @@ -56,6 +61,7 @@ func newTestStore(t testing.TB) (*Storage, error) {
func TestSetCouchbase_ShouldReturnNoError(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

err = testStore.Set("test", []byte("test"), 0)

Expand All @@ -65,6 +71,7 @@ func TestSetCouchbase_ShouldReturnNoError(t *testing.T) {
func TestGetCouchbase_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

val, err := testStore.Get("not_found_key")

Expand All @@ -75,6 +82,7 @@ func TestGetCouchbase_ShouldReturnNil_WhenDocumentNotFound(t *testing.T) {
func TestSetAndGet_GetShouldReturn_SetValueWithoutError(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

err = testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
Expand All @@ -88,6 +96,7 @@ func TestSetAndGet_GetShouldReturn_SetValueWithoutError(t *testing.T) {
func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

err = testStore.Set("test", []byte("fiber_test_value"), 3*time.Second)
require.NoError(t, err)
Expand All @@ -103,6 +112,7 @@ func TestSetAndGet_GetShouldReturnNil_WhenTTLExpired(t *testing.T) {
func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

err = testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
Expand All @@ -117,6 +127,7 @@ func TestSetAndDelete_DeleteShouldReturn_NoError(t *testing.T) {
func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

err = testStore.Set("test", []byte("fiber_test_value"), 0)
require.NoError(t, err)
Expand All @@ -131,6 +142,7 @@ func TestSetAndReset_ResetShouldReturn_NoError(t *testing.T) {
func TestClose_CloseShouldReturn_NoError(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

err = testStore.Close()
require.NoError(t, err)
Expand All @@ -139,13 +151,15 @@ func TestClose_CloseShouldReturn_NoError(t *testing.T) {
func TestGetConn_ReturnsNotNil(t *testing.T) {
testStore, err := newTestStore(t)
require.NoError(t, err)
defer testStore.Close()

require.True(t, testStore.Conn() != nil)
}

func Benchmark_Couchbase_Set(b *testing.B) {
testStore, err := newTestStore(b)
require.NoError(b, err)
defer testStore.Close()

b.ReportAllocs()
b.ResetTimer()
Expand All @@ -160,6 +174,7 @@ func Benchmark_Couchbase_Set(b *testing.B) {
func Benchmark_Couchbase_Get(b *testing.B) {
testStore, err := newTestStore(b)
require.NoError(b, err)
defer testStore.Close()

err = testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
Expand All @@ -177,6 +192,7 @@ func Benchmark_Couchbase_Get(b *testing.B) {
func Benchmark_Couchbase_SetAndDelete(b *testing.B) {
testStore, err := newTestStore(b)
require.NoError(b, err)
defer testStore.Close()

b.ReportAllocs()
b.ResetTimer()
Expand Down
Loading
Loading