Skip to content

Commit 7103ce0

Browse files
committed
[!] use testcontainers for integration tests (#718)
1 parent 6d7b4a8 commit 7103ce0

File tree

16 files changed

+498
-204
lines changed

16 files changed

+498
-204
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -17,111 +17,17 @@ concurrency:
1717
group: ${{ github.workflow }}-${{ github.ref }}
1818
cancel-in-progress: true
1919

20-
jobs:
21-
22-
test-postgresql-windows:
23-
if: true # false to skip job during debug
24-
name: Test on Windows
25-
runs-on: windows-latest
26-
steps:
27-
28-
- name: Start PostgreSQL on Windows
29-
run: |
30-
$pgService = Get-Service -Name postgresql*
31-
Set-Service -InputObject $pgService -Status running -StartupType automatic
32-
Start-Process -FilePath "$env:PGBIN\pg_isready" -Wait -PassThru
33-
34-
- name: Create scheduler user on Windows
35-
run: |
36-
& $env:PGBIN\psql --command="CREATE USER scheduler PASSWORD 'somestrong'" --command="\du"
37-
38-
- name: Create timetable database
39-
run: |
40-
& $env:PGBIN\createdb --owner=scheduler timetable
41-
$env:PGPASSWORD = 'somestrong'
42-
& $env:PGBIN\psql --username=scheduler --host=localhost --list timetable
43-
44-
- name: Check out code
45-
uses: actions/checkout@v5
46-
47-
- name: Set up Golang
48-
uses: actions/setup-go@v6
49-
with:
50-
go-version: '1.25'
51-
52-
- name: Test
53-
run: go test -v -p 1 -parallel 1 -failfast ./...
54-
55-
56-
57-
test-postgresql-macos:
58-
if: true # false to skip job during debug
59-
name: Test on MacOS
60-
runs-on: macos-latest
61-
steps:
62-
63-
- name: Start PostgreSQL on MacOS
64-
run: |
65-
brew update
66-
brew install postgresql@16
67-
brew link --force postgresql@16
68-
brew services start postgresql@16
69-
echo "Check PostgreSQL service is running"
70-
i=10
71-
COMMAND='pg_isready'
72-
while [ $i -gt 0 ]; do
73-
echo "Check PostgreSQL service status"
74-
eval $COMMAND && break
75-
((i--))
76-
if [ $i == 0 ]; then
77-
echo "PostgreSQL service not ready, all attempts exhausted"
78-
exit 1
79-
fi
80-
echo "PostgreSQL service not ready, wait 10 more sec, attempts left: $i"
81-
sleep 10
82-
done
83-
84-
# Homebrew creates an account with the same name as the installing user, but no password
85-
- name: Create scheduler user
86-
run: |
87-
psql --command="CREATE USER scheduler PASSWORD 'somestrong'" --command="\du" postgres
88-
89-
- name: Create timetable database
90-
run: |
91-
createdb --owner=scheduler timetable
92-
PGPASSWORD=somestrong psql --username=scheduler --host=localhost --list timetable
20+
# This workflow uses testcontainers-go for PostgreSQL testing
21+
# Docker provides consistent environment - only Ubuntu needed
9322

94-
- name: Check out code
95-
uses: actions/checkout@v5
96-
97-
- name: Set up Golang
98-
uses: actions/setup-go@v6
99-
with:
100-
go-version: '1.25'
101-
102-
- name: Test
103-
run: go test -v -p 1 -parallel 1 -failfast ./...
23+
jobs:
10424

105-
test-postgresql-ubuntu:
25+
test:
10626
if: true # false to skip job during debug
107-
name: Test and Build on Ubuntu
27+
name: Test and Build with Testcontainers
10828
runs-on: ubuntu-latest
10929
steps:
11030

111-
- name: Start PostgreSQL on Ubuntu
112-
run: |
113-
sudo systemctl start postgresql.service
114-
pg_isready
115-
116-
- name: Create scheduler user
117-
run: |
118-
sudo -u postgres psql --command="CREATE USER scheduler PASSWORD 'somestrong'" --command="\du"
119-
120-
- name: Create timetable database
121-
run: |
122-
sudo -u postgres createdb --owner=scheduler timetable
123-
PGPASSWORD=somestrong psql --username=scheduler --host=localhost --list timetable
124-
12531
- name: Check out code
12632
uses: actions/checkout@v5
12733

@@ -140,23 +46,42 @@ jobs:
14046
with:
14147
version: latest
14248

143-
- name: Test
144-
run: go test -failfast -v -timeout=300s -p 1 -coverprofile=profile.cov ./...
49+
- name: Test with Testcontainers
50+
run: go test -failfast -v -timeout=300s -coverprofile=profile.cov ./...
14551

146-
- name: Coveralls
147-
uses: shogo82148/actions-goveralls@v1
52+
- name: Upload coverage profile
53+
uses: actions/upload-artifact@v4
14854
with:
149-
path-to-profile: profile.cov
55+
name: coverage-profile-${{ github.run_id }}
56+
path: profile.cov
57+
retention-days: 1
15058

15159
- name: Run GoReleaser
15260
uses: goreleaser/goreleaser-action@v6
15361
with:
15462
version: latest
15563
args: release --snapshot --skip=publish --clean
15664

65+
coverage:
66+
if: true # false to skip job during debug
67+
name: Coverage Report
68+
runs-on: ubuntu-latest
69+
needs: [test]
70+
steps:
71+
72+
- name: Download coverage profile
73+
uses: actions/download-artifact@v4
74+
with:
75+
name: coverage-profile-${{ github.run_id }}
76+
77+
- name: Send coverage to Coveralls
78+
uses: coverallsapp/github-action@v2
79+
with:
80+
file: profile.cov
81+
15782
build-docs:
15883
if: true # false to skip job during debug
159-
needs: [test-postgresql-ubuntu, test-postgresql-windows, test-postgresql-macos]
84+
needs: [test]
16085
name: Build Docs
16186
runs-on: ubuntu-latest
16287
steps:
@@ -201,7 +126,7 @@ jobs:
201126

202127
test-docker-images:
203128
if: true # false to skip job during debug
204-
needs: [test-postgresql-ubuntu, test-postgresql-windows, test-postgresql-macos]
129+
needs: [test]
205130
name: Test Docker Image Build
206131
runs-on: ubuntu-latest
207132
steps:

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"files.eol": "\n"
2+
"files.eol": "\n",
3+
"terminal.integrated.defaultProfile.windows": "PowerShell"
34
}

go.mod

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,76 @@ require (
1414
github.com/sirupsen/logrus v1.9.3
1515
github.com/spf13/viper v1.21.0
1616
github.com/stretchr/testify v1.11.1
17+
github.com/testcontainers/testcontainers-go v0.39.0
18+
github.com/testcontainers/testcontainers-go/modules/postgres v0.39.0
1719
gopkg.in/natefinch/lumberjack.v2 v2.2.1
1820
)
1921

2022
require (
23+
dario.cat/mergo v1.0.2 // indirect
24+
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
25+
github.com/Microsoft/go-winio v0.6.2 // indirect
26+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
27+
github.com/containerd/errdefs v1.0.0 // indirect
28+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
29+
github.com/containerd/log v0.1.0 // indirect
30+
github.com/containerd/platforms v0.2.1 // indirect
31+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
2132
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
33+
github.com/distribution/reference v0.6.0 // indirect
34+
github.com/docker/docker v28.4.0+incompatible // indirect
35+
github.com/docker/go-connections v0.6.0 // indirect
36+
github.com/docker/go-units v0.5.0 // indirect
37+
github.com/ebitengine/purego v0.9.0 // indirect
38+
github.com/felixge/httpsnoop v1.0.4 // indirect
2239
github.com/fsnotify/fsnotify v1.9.0 // indirect
40+
github.com/go-logr/logr v1.4.3 // indirect
41+
github.com/go-logr/stdr v1.2.2 // indirect
42+
github.com/go-ole/go-ole v1.3.0 // indirect
2343
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
44+
github.com/google/uuid v1.6.0 // indirect
45+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
2446
github.com/jackc/pgpassfile v1.0.0 // indirect
2547
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
2648
github.com/jackc/puddle/v2 v2.2.2 // indirect
49+
github.com/klauspost/compress v1.18.0 // indirect
50+
github.com/lufia/plan9stats v0.0.0-20250827001030-24949be3fa54 // indirect
51+
github.com/magiconair/properties v1.8.10 // indirect
52+
github.com/moby/docker-image-spec v1.3.1 // indirect
53+
github.com/moby/go-archive v0.1.0 // indirect
54+
github.com/moby/patternmatcher v0.6.0 // indirect
55+
github.com/moby/sys/sequential v0.6.0 // indirect
56+
github.com/moby/sys/user v0.4.0 // indirect
57+
github.com/moby/sys/userns v0.1.0 // indirect
58+
github.com/moby/term v0.5.2 // indirect
59+
github.com/morikuni/aec v1.0.0 // indirect
60+
github.com/opencontainers/go-digest v1.0.0 // indirect
61+
github.com/opencontainers/image-spec v1.1.1 // indirect
2762
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
2863
github.com/pkg/errors v0.9.1 // indirect
2964
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
65+
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
3066
github.com/sagikazarmark/locafero v0.12.0 // indirect
67+
github.com/shirou/gopsutil/v4 v4.25.8 // indirect
3168
github.com/spf13/afero v1.15.0 // indirect
3269
github.com/spf13/cast v1.10.0 // indirect
3370
github.com/spf13/pflag v1.0.10 // indirect
3471
github.com/subosito/gotenv v1.6.0 // indirect
72+
github.com/tklauser/go-sysconf v0.3.15 // indirect
73+
github.com/tklauser/numcpus v0.10.0 // indirect
74+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
75+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
76+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
77+
go.opentelemetry.io/otel v1.38.0 // indirect
78+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
79+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
3580
go.yaml.in/yaml/v3 v3.0.4 // indirect
3681
golang.org/x/crypto v0.42.0 // indirect
3782
golang.org/x/sync v0.17.0 // indirect
3883
golang.org/x/sys v0.36.0 // indirect
3984
golang.org/x/text v0.29.0 // indirect
85+
google.golang.org/grpc v1.75.0 // indirect
86+
google.golang.org/protobuf v1.36.7 // indirect
4087
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
4188
gopkg.in/yaml.v3 v3.0.1 // indirect
4289
)

0 commit comments

Comments
 (0)