Skip to content

Commit 046e431

Browse files
committed
feat: coverage
1 parent 6b11d4a commit 046e431

File tree

13 files changed

+70
-114
lines changed

13 files changed

+70
-114
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ jobs:
101101
needs: [clippy, check]
102102
name: tests
103103
runs-on: ubuntu-latest
104-
strategy:
105-
fail-fast: false
106-
matrix:
107-
test: [test-all, unittest]
108104
steps:
109105
- name: Install toolchain
110106
uses: actions-rust-lang/setup-rust-toolchain@v1
@@ -116,10 +112,18 @@ jobs:
116112

117113
- uses: extractions/setup-just@v2
118114

115+
- name: Install cargo-llvm-cov
116+
uses: taiki-e/install-action@cargo-llvm-cov
117+
119118
- name: Install Protoc
120119
uses: arduino/setup-protoc@v3
121120
with:
122121
repo-token: ${{ secrets.GITHUB_TOKEN }}
123122

124123
- name: Tests
125-
run: just ${{ matrix.test }}
124+
run: just test-all
125+
126+
- name: Upload coverage reports to Codecov
127+
uses: codecov/codecov-action@v5
128+
with:
129+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/nightly.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ jobs:
5454
needs: [clippy, check]
5555
name: tests
5656
runs-on: ubuntu-latest
57-
strategy:
58-
fail-fast: false
59-
matrix:
60-
test: [test-all, unittest]
6157
steps:
6258
- name: Install toolchain
6359
uses: actions-rust-lang/setup-rust-toolchain@v1
@@ -69,13 +65,16 @@ jobs:
6965

7066
- uses: extractions/setup-just@v2
7167

68+
- name: Install cargo-llvm-cov
69+
uses: taiki-e/install-action@cargo-llvm-cov
70+
7271
- name: Install Protoc
7372
uses: arduino/setup-protoc@v3
7473
with:
7574
repo-token: ${{ secrets.GITHUB_TOKEN }}
7675

7776
- name: Tests
78-
run: just ${{ matrix.test }}
77+
run: just test-all
7978

8079
docker:
8180
needs: [tests]

.github/workflows/release.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ jobs:
5454
needs: [clippy, check]
5555
name: tests
5656
runs-on: ubuntu-latest
57-
strategy:
58-
fail-fast: false
59-
matrix:
60-
test: [test-all, unittest]
6157
steps:
6258
- name: Install toolchain
6359
uses: actions-rust-lang/setup-rust-toolchain@v1
@@ -69,13 +65,16 @@ jobs:
6965

7066
- uses: extractions/setup-just@v2
7167

68+
- name: Install cargo-llvm-cov
69+
uses: taiki-e/install-action@cargo-llvm-cov
70+
7271
- name: Install Protoc
7372
uses: arduino/setup-protoc@v3
7473
with:
7574
repo-token: ${{ secrets.GITHUB_TOKEN }}
7675

7776
- name: Tests
78-
run: just ${{ matrix.test }}
77+
run: just test-all
7978

8079
docker:
8180
needs: [tests]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ debug/
1515

1616
# nvim config
1717
.sqllsrc.json
18+
19+
coverage.info

Dockerfile

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ WORKDIR build
1212

1313
ARG features=all-databases,otlp,caching-skytable
1414

15-
RUN USER=root cargo init --bin --name feedback-fusion
16-
RUN USER=root cargo init --lib --name feedback_fusion_common common
17-
RUN USER=root cargo init --lib --name feedback_fusion_codegen codegen
18-
1915
COPY ./.cargo ./.cargo
2016
COPY ./Cargo.toml .
2117
COPY ./Cargo.lock .
@@ -24,21 +20,9 @@ COPY ./common ./common
2420
COPY ./codegen ./codegen
2521
COPY ./fuzz ./fuzz
2622
COPY ./benches ./benches
27-
28-
ARG TARGETARCH
29-
30-
RUN if [ "$TARGETARCH" = "arm64" ]; then \
31-
cargo build --release --target aarch64-unknown-linux-gnu --features $features; \
32-
else \
33-
cargo build --release --features $features; \
34-
fi
35-
36-
RUN rm -Rf ./src
3723
COPY ./src ./src
3824

39-
# for some reason cargo does not detect the file change
40-
RUN touch src/main.rs
41-
25+
ARG TARGETARCH
4226
RUN if [ "$TARGETARCH" = "arm64" ]; then \
4327
cargo build --release --target aarch64-unknown-linux-gnu --features $features; \
4428
mv target/aarch64-unknown-linux-gnu/release/feedback-fusion target/release/feedback-fusion; \

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ FeedbackFusion is licensed under the MIT License.
5252
- helm
5353
- cargo
5454
- docker
55-
- cargo-release
55+
- cargo-llvm-cov
56+
- cargo-release (only for releases)
5657

5758
### Setup
5859

@@ -74,7 +75,7 @@ The integration tests are executed for each database backend on its own therefor
7475
just test postgres # possible values: postgres, mariadb, mysql, mssql, skytable (this uses postgres and skytable caching)
7576
```
7677

77-
or you can executed all of them:
78+
or you can executed all of them, which automatically generates a coverage report based on cargo-llvm-cov:
7879

7980
```sh
8081
just # or `just test-all`

justfile

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ LOCAL_DOCKER_IMAGE := "feedback-fusion"
33
LOCAL_PLATFORM := "linux/" + replace(replace(arch(), "x86_64", "amd64"), "aarch64", "arm64")
44
DEFAULT_TEST := "postgres"
55

6-
test-all:
6+
test-all: cleanup
7+
cargo llvm-cov clean --workspace
8+
9+
just unittest
710
just test postgres
811
just test mariadb
912
just test mysql
1013
just test mssql
1114
just test skytable
1215

16+
cargo llvm-cov report
17+
cargo llvm-cov report --lcov --output-path coverage.info
18+
1319
init:
1420
pre-commit install
1521

@@ -28,8 +34,8 @@ clippy:
2834
#
2935

3036
build PLATFORM=LOCAL_PLATFORM DOCKERFILE="./Dockerfile":
31-
@echo "Building for {{PLATFORM}}"
32-
docker buildx build -t {{LOCAL_DOCKER_IMAGE}} --platform {{PLATFORM}} -f {{DOCKERFILE}} --load .
37+
@echo "building for {{PLATFORM}}"
38+
docker buildx build -t {{LOCAL_DOCKER_IMAGE}} --platform {{PLATFORM}} -f {{DOCKERFILE}} --load --build-arg COVERAGE=true .
3339

3440
build-all DOCKERFILE="./Dockerfile":
3541
just build linux/arm64,linux/amd64 {{DOCKERFILE}}
@@ -39,11 +45,19 @@ build-all DOCKERFILE="./Dockerfile":
3945
#
4046

4147
backend TYPE=DEFAULT_TEST:
42-
just build
48+
FEEDBACK_FUSION_CONFIG="./tests/_common/configs/{{TYPE}}.yaml" RUST_LOG=DEBUG cargo llvm-cov run --no-report > ./target/feedback-fusion.log 2>&1 &
4349

44-
docker run --name {{LOCAL_DOCKER_IMAGE}} -d -e FEEDBACK_FUSION_CONFIG="/etc/feedback-fusion/config.yaml" -v ./tests/_common/configs/{{TYPE}}.yaml:/etc/feedback-fusion/config.yaml -e RUST_LOG=DEBUG --network {{DOCKER_NETWORK}} -p 8000:8000 {{LOCAL_DOCKER_IMAGE}}
50+
while ! nc -z localhost 8000; do \
51+
sleep 1; \
52+
done
53+
@echo "Application ready"
4554

46-
bench: docker oidc-server-mock postgres && cleanup
55+
stop-backend:
56+
@PID=$(lsof -t -i:8000) && if [ -n "$PID" ]; then \
57+
kill -2 $PID; \
58+
fi
59+
60+
bench: oidc-server-mock postgres && cleanup
4761
just backend postgres
4862
GRPC_ENDPOINT=http://localhost:8000 OIDC_CLIENT_ID=client OIDC_CLIENT_SECRET=secret OIDC_PROVIDER=http://localhost:5151 cargo bench
4963

@@ -54,32 +68,29 @@ protoc-docs:
5468
# Testing requirements
5569
#
5670

57-
@docker: cleanup
58-
docker network create {{DOCKER_NETWORK}} > /dev/null
59-
6071
@oidc-server-mock:
6172
docker compose -f tests/_common/oidc-mock/docker-compose.yaml up -d
62-
sleep 5
73+
@sleep 5
6374
curl -s -o /dev/null http://localhost:5151/.well-known/openid-configuration
6475

6576
@postgres:
66-
docker run --name database -e POSTGRES_PASSWORD=password -e POSTGRES_USERNAME=postgres --network {{DOCKER_NETWORK}} -d postgres
77+
docker run --name database -e POSTGRES_PASSWORD=password -e POSTGRES_USERNAME=postgres -p 5150:5432 -d postgres
6778
sleep 5
6879

6980
@mysql:
70-
docker run --name database -e MYSQL_ROOT_PASSWORD=password -e MYSQL_PASSWORD=password -e MYSQL_USER=username -e MYSQL_DATABASE=database --network {{DOCKER_NETWORK}} -d mysql
81+
docker run --name database -e MYSQL_ROOT_PASSWORD=password -e MYSQL_PASSWORD=password -e MYSQL_USER=username -e MYSQL_DATABASE=database -p 5150:3306 -d mysql
7182
sleep 30
7283

7384
@mariadb:
74-
docker run --name database -e MYSQL_ROOT_PASSWORD=password -e MYSQL_PASSWORD=password -e MYSQL_USER=username -e MYSQL_DATABASE=database --network {{DOCKER_NETWORK}} -d mariadb
85+
docker run --name database -e MYSQL_ROOT_PASSWORD=password -e MYSQL_PASSWORD=password -e MYSQL_USER=username -e MYSQL_DATABASE=database -p 5150:3306 -d mariadb
7586
sleep 10
7687

7788
@mssql:
78-
docker run --name database -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Password1 --network {{DOCKER_NETWORK}} -d mcr.microsoft.com/mssql/server:2022-latest
89+
docker run --name database -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Password1 -p 5150:1433 -d mcr.microsoft.com/mssql/server:2022-latest
7990
sleep 10
8091

8192
@skytable: postgres
82-
docker run -p 2003:2003 --entrypoint skyd --rm --name skytable --network {{DOCKER_NETWORK}} -d skytable/skytable --auth-root-password=passwordpassword --endpoint=tcp@0.0.0.0:2003
93+
docker run -p 2003:2003 --entrypoint skyd --rm --name skytable -d skytable/skytable --auth-root-password=passwordpassword --endpoint=tcp@0.0.0.0:2003
8394

8495
#
8596
# Testing
@@ -88,24 +99,28 @@ protoc-docs:
8899
@cleanup:
89100
-docker rm -f database > /dev/null 2>&1
90101
-docker rm -f oidc-server-mock > /dev/null 2>&1
91-
-docker rm -f feedback-fusion > /dev/null 2>&1
102+
-just stop-backend
92103
-docker rm -f skytable > /dev/null 2>&1
93104
-docker network rm {{DOCKER_NETWORK}} > /dev/null 2>&1
94105

95106
unittest:
96-
cargo test --bin feedback-fusion
107+
cargo llvm-cov --bin feedback-fusion --no-report
97108

98109
integration:
99-
OIDC_PROVIDER="http://localhost:5151" OIDC_CLIENT_ID="client" OIDC_CLIENT_SECRET="secret" RUST_LOG="INFO" GRPC_ENDPOINT="http://localhost:8000" cargo test --no-fail-fast --test integration_test || (docker logs feedback-fusion; exit 1)
110+
OIDC_PROVIDER="http://localhost:5151" OIDC_CLIENT_ID="client" OIDC_CLIENT_SECRET="secret" RUST_LOG="INFO" GRPC_ENDPOINT="http://localhost:8000" cargo llvm-cov --no-report --no-fail-fast --test integration_test || (cat ./target/feedback-fusion.log; just stop-backend; cargo llvm-cov report; exit 1)
100111

101-
test TYPE=DEFAULT_TEST: docker oidc-server-mock
112+
test TYPE=DEFAULT_TEST: oidc-server-mock
102113
just {{TYPE}}
103-
if [ "{{TYPE}}" = "mariadb" ]; then just backend mysql; else just backend {{TYPE}}; fi
104-
sleep 1
114+
@if [ "{{TYPE}}" = "mariadb" ]; then just backend mysql; else just backend {{TYPE}}; fi
115+
105116
just integration
106117

118+
just stop-backend
107119
-docker rm -f database > /dev/null 2>&1
108-
-docker rm -f feedback-fusion > /dev/null 2>&1
120+
121+
coverage:
122+
genhtml -q --output-directory coverage ./target/coverage.lcov
123+
cd coverage && python3 -m http.server 3000
109124

110125
fuzz:
111126
OIDC_PROVIDER="http://localhost:5151" OIDC_CLIENT_ID="client" OIDC_CLIENT_SECRET="secret" RUST_LOG="INFO" GRPC_ENDPOINT="http://localhost:8000" cargo fuzz run fuzz_create_and_export
@@ -156,7 +171,7 @@ dashboard: lib
156171

157172
pnpm run -C dashboard build
158173

159-
dashboard-dev: docker oidc-server-mock postgres && cleanup
174+
dashboard-dev: oidc-server-mock postgres && cleanup
160175
just backend postgres
161176
NUXT_PUBLIC_FEEDBACK_FUSION_ENDPOINT="http://localhost:8000" \
162177
FEEDBACK_FUSION_OIDC_PROVIDER_AUTHORIZATION_URL="http://localhost:5151/connect/authorize" \

tests/_common/configs/mssql.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ database:
33
username: sa
44
password: Password1
55
database: master
6-
endpoint: database:1433
6+
endpoint: localhost:5150
77
oidc:
8-
provider: http://oidc-server-mock
8+
provider: http://localhost:5151
99
issuer: http://localhost:5151
1010
scopes:
1111
- name: "api:feedback-fusion"

tests/_common/configs/mysql.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ database:
33
username: username
44
password: password
55
database: database
6-
endpoint: database:3306
6+
endpoint: localhost:5150
77
oidc:
8-
provider: http://oidc-server-mock
8+
provider: http://localhost:5151
99
issuer: http://localhost:5151
1010
scopes:
1111
- name: "api:feedback-fusion"

tests/_common/configs/postgres-undockerized.yaml

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)