Skip to content

Commit 5d584c5

Browse files
committed
test postgres unit test
1 parent 87bc3d2 commit 5d584c5

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

.github/workflows/checks.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,137 @@ jobs:
201201

202202
- name: Rust Clippy ${{ matrix.target }}
203203
run: make clippy_${{ matrix.target }}
204+
205+
build-and-test-postgres:
206+
runs-on: ubuntu-latest
207+
permissions:
208+
contents: read
209+
checks: write
210+
211+
services:
212+
postgres:
213+
image: postgres:18.0
214+
env:
215+
POSTGRES_USER: test
216+
POSTGRES_PASSWORD: test
217+
POSTGRES_DB: syncstorage
218+
ports:
219+
- 5432:5432
220+
options: >-
221+
--health-cmd="pg_isready -U test"
222+
--health-interval=10s
223+
--health-timeout=5s
224+
--health-retries=5
225+
226+
env:
227+
SYNC_SYNCSTORAGE__DATABASE_URL: postgres://test:test@127.0.0.1/syncstorage
228+
SYNC_TOKENSERVER__DATABASE_URL: postgres://test:test@127.0.0.1/tokenserver
229+
SYNC_TOKENSERVER__NODE_TYPE: postgres
230+
RUST_BACKTRACE: 1
231+
RUST_TEST_THREADS: 1
232+
233+
steps:
234+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
235+
with:
236+
persist-credentials: false
237+
238+
- name: Restore Rust toolchain
239+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
240+
with:
241+
path: |
242+
~/.rustup/toolchains
243+
~/.rustup/update-hashes
244+
key: ${{ runner.os }}-rust-toolchain-${{ env.RUST_VERSION }}
245+
246+
- name: Restore pip and Poetry virtualenv
247+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
248+
with:
249+
path: |
250+
~/.cache/pip
251+
~/.cache/pypoetry/virtualenvs
252+
key: ${{ runner.os }}-python-${{ hashFiles('pyproject.toml', 'poetry.lock') }}
253+
254+
- name: Install PostgreSQL client
255+
run: sudo apt-get update && sudo apt-get install -y postgresql-client
256+
257+
- name: Create Tokenserver database
258+
run: |
259+
PGPASSWORD=test psql -U test -h 127.0.0.1 -d syncstorage -c 'CREATE DATABASE tokenserver;'
260+
261+
- name: Create version.json
262+
run: |
263+
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \
264+
"${GITHUB_SHA}" \
265+
"${GITHUB_REF_NAME}" \
266+
"${GITHUB_REPOSITORY_OWNER}" \
267+
"${GITHUB_REPOSITORY_NAME}" \
268+
"${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
269+
> version.json
270+
env:
271+
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
272+
273+
- name: Install cargo-nextest
274+
run: curl -LsSf https://get.nexte.st/latest/linux | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin
275+
276+
- name: Install cargo-llvm-cov
277+
run: cargo install --locked cargo-llvm-cov
278+
279+
- name: Run unit tests with coverage
280+
run: make postgres_test_with_coverage
281+
282+
- name: Run unit tests with coverage (quota enforced)
283+
run: make postgres_test_with_coverage
284+
env:
285+
SYNC_SYNCSTORAGE__ENFORCE_QUOTA: 1
286+
287+
- name: Run Postgres utils tests
288+
working-directory: tools/postgres
289+
run: |
290+
poetry install --no-interaction --no-ansi
291+
WORKFLOW=$(echo "${GITHUB_WORKFLOW}" | tr ' ' '-' | tr '[:upper:]' '[:lower:]')
292+
poetry run pytest test_purge_ttl.py -v --junit-xml="../../workflow/test-results/${GITHUB_RUN_NUMBER}__$(date +%s)__$(basename ${GITHUB_REPOSITORY})__${WORKFLOW}__postgres_utils__results.xml"
293+
env:
294+
SYNC_SYNCSTORAGE__DATABASE_URL: postgresql://test:test@127.0.0.1/syncstorage
295+
296+
- name: Publish Test Report
297+
uses: dorny/test-reporter@a810f9bf83f2344124a920a7a0a85a6716e791f0
298+
if: always()
299+
with:
300+
name: Postgres Unit Tests
301+
path: workflow/test-results/*.xml
302+
reporter: java-junit
303+
fail-on-error: false
304+
305+
- name: Upload test results
306+
if: always()
307+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
308+
with:
309+
name: postgres-test-results
310+
path: workflow/test-results/
311+
312+
# Upload to GCS on master
313+
- name: Authenticate to Google Cloud
314+
if: github.ref == 'refs/heads/master'
315+
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
316+
with:
317+
credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }}
318+
319+
- name: Upload JUnit results to GCS
320+
if: github.ref == 'refs/heads/master'
321+
uses: google-github-actions/upload-cloud-storage@c0f6160ff80057923ff50e5e567695cea181ec23 # v2
322+
with:
323+
path: workflow/test-results
324+
destination: ecosystem-test-eng-metrics/syncstorage-rs/junit
325+
glob: "*.xml"
326+
parent: false
327+
process_gcloudignore: false
328+
329+
- name: Upload coverage results to GCS
330+
if: github.ref == 'refs/heads/master'
331+
uses: google-github-actions/upload-cloud-storage@c0f6160ff80057923ff50e5e567695cea181ec23 # v2
332+
with:
333+
path: workflow/test-results
334+
destination: ecosystem-test-eng-metrics/syncstorage-rs/coverage
335+
glob: "*.json"
336+
parent: false
337+
process_gcloudignore: false

0 commit comments

Comments
 (0)