Skip to content

Commit 12bf3e2

Browse files
authored
test: replace sqlx test with testcontainers (#787)
* test: replace sqlx::test with postgres testcontainers Signed-off-by: Joseph Livesey <[email protected]> * ci: update ci for testcontainers setup Signed-off-by: Joseph Livesey <[email protected]> * test(tap-agent): fix mock sender allocation --------- Signed-off-by: Joseph Livesey <[email protected]>
1 parent c3a4f1c commit 12bf3e2

File tree

24 files changed

+1332
-461
lines changed

24 files changed

+1332
-461
lines changed

.github/workflows/tests.yml

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
4242
- name: Install libsasl2-dev
4343
run: apt-get update && apt-get install -y libsasl2-dev
44+
- name: Install protobuf compiler
45+
run: apt-get update && apt-get install protobuf-compiler -y
4446
- name: Cache dependencies
4547
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
4648
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
@@ -52,8 +54,6 @@ jobs:
5254
- name: Run sccache-cache
5355
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
5456
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
55-
- name: Install protobuf compiler
56-
run: apt-get update && apt-get install protobuf-compiler -y
5757
- name: Install sqlx
5858
run: cargo install sqlx-cli --no-default-features --features postgres
5959
- name: Run the test sqlx migrations
@@ -73,6 +73,8 @@ jobs:
7373
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
7474
- name: Install libsasl2-dev
7575
run: apt-get update && apt-get install -y libsasl2-dev
76+
- name: Install protobuf compiler
77+
run: apt-get update && apt-get install protobuf-compiler -y
7678
- name: Cache dependencies
7779
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
7880
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
@@ -84,8 +86,6 @@ jobs:
8486
- name: Run sccache-cache
8587
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
8688
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
87-
- name: Install protobuf compiler
88-
run: apt-get update && apt-get install protobuf-compiler -y
8989
- run: |
9090
rustup component add clippy
9191
# Temporarily allowing dead-code, while denying all other warnings
@@ -94,31 +94,28 @@ jobs:
9494
test-and-coverage:
9595
name: cargo test and coverage
9696
runs-on: ubuntu-latest
97-
permissions:
98-
contents: write
99-
pull-requests: write
100-
actions: read
101-
services:
102-
postgres:
103-
image: postgres:15
104-
env:
105-
POSTGRES_HOST_AUTH_METHOD: trust
106-
options: >-
107-
--health-cmd pg_isready
108-
--health-interval 10s
109-
--health-timeout 5s
110-
--health-retries 5
111-
ports:
112-
- 5432:5432
11397
container:
11498
image: rust:1.86-bookworm
99+
options: --privileged -v /var/run/docker.sock:/var/run/docker.sock
115100
env:
116-
DATABASE_URL: postgres://postgres@postgres:5432
117101
CI: true
102+
SQLX_OFFLINE: true
103+
DOCKER_HOST: unix:///var/run/docker.sock
118104
steps:
119105
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
106+
- name: Install Docker CLI and verify
107+
run: |
108+
apt-get update
109+
apt-get install -y docker.io
110+
# Verify Docker is accessible
111+
docker version
112+
docker ps
113+
# Pre-pull the postgres:15 image to avoid timeouts
114+
docker pull postgres:15
120115
- name: Install libsasl2-dev
121116
run: apt-get update && apt-get install -y libsasl2-dev
117+
- name: Install protobuf compiler
118+
run: apt-get update && apt-get install protobuf-compiler -y
122119
- name: Cache dependencies
123120
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
124121
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
@@ -127,17 +124,11 @@ jobs:
127124
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
128125
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
129126
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
130-
- name: Install protobuf compiler
131-
run: apt-get update && apt-get install protobuf-compiler -y
132127
- name: Run sccache-cache
133128
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
134129
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
135130
- name: Install cargo-llvm-cov
136131
uses: taiki-e/install-action@cargo-llvm-cov
137-
- name: Install sqlx
138-
run: cargo install sqlx-cli --no-default-features --features postgres
139-
- name: Run the test sqlx migrations
140-
run: cargo sqlx migrate run
141132
- name: Run tests and generate coverage report
142133
run: cargo llvm-cov test --all-features --workspace --lcov --output-path lcov.info
143134
- name: Upload coverage to Coveralls
@@ -149,30 +140,27 @@ jobs:
149140
test-docs:
150141
name: cargo test docs code snippets
151142
runs-on: ubuntu-latest
152-
permissions:
153-
contents: write
154-
pull-requests: write
155-
actions: read
156-
services:
157-
postgres:
158-
image: postgres:15
159-
env:
160-
POSTGRES_HOST_AUTH_METHOD: trust
161-
options: >-
162-
--health-cmd pg_isready
163-
--health-interval 10s
164-
--health-timeout 5s
165-
--health-retries 5
166-
ports:
167-
- 5432:5432
168143
container:
169144
image: rust:1.86-bookworm
145+
options: --privileged -v /var/run/docker.sock:/var/run/docker.sock
170146
env:
171-
DATABASE_URL: postgres://postgres@postgres:5432
147+
SQLX_OFFLINE: true
148+
DOCKER_HOST: unix:///var/run/docker.sock
172149
steps:
173150
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
151+
- name: Install Docker CLI and verify
152+
run: |
153+
apt-get update
154+
apt-get install -y docker.io
155+
# Verify Docker is accessible
156+
docker version
157+
docker ps
158+
# Pre-pull the postgres:15 image to avoid timeouts
159+
docker pull postgres:15
174160
- name: Install libsasl2-dev
175161
run: apt-get update && apt-get install -y libsasl2-dev
162+
- name: Install protobuf compiler
163+
run: apt-get update && apt-get install protobuf-compiler -y
176164
- name: Cache dependencies
177165
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
178166
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
@@ -181,14 +169,8 @@ jobs:
181169
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
182170
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
183171
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
184-
- name: Install protobuf compiler
185-
run: apt-get update && apt-get install protobuf-compiler -y
186172
- name: Run sccache-cache
187173
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
188174
if: ${{ !startsWith(github.head_ref, 'renovate/') }}
189-
- name: Install sqlx
190-
run: cargo install sqlx-cli --no-default-features --features postgres
191-
- name: Run the test sqlx migrations
192-
run: cargo sqlx migrate run
193175
- name: Test documentation code snippets
194176
run: cargo test --doc --all-features --workspace

0 commit comments

Comments
 (0)