From 437fdb0b29aef247b5c52bffa26aa45e8110a645 Mon Sep 17 00:00:00 2001
From: Neil-Jocelyn Schark <neil.schark@h-da.de>
Date: Thu, 17 Apr 2025 12:29:10 +0000
Subject: [PATCH] Resolve "Add code coverage checks and badges"

---
 .gitignore     |  2 ++
 .gitlab-ci.yml | 11 ++++++++++-
 README.md      |  3 +++
 justfile       |  5 ++++-
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 7973f4e0..2029f35e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 gen/*
 bin/*
+
+cover.profile
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ada667b2..22d394ab 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -46,8 +46,17 @@ test-go:
     stage: test
     image:
         name: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/golang:${GOLANG_VERSION}
+    before_script:
+        - go install github.com/t-yuki/gocover-cobertura@latest
     script:
-        - go test ./...
+        - go test ./... -coverprofile=cover.profile && go tool cover -func cover.profile
+        - gocover-cobertura < cover.profile > coverage.xml
+    coverage: /total:\s+\(statements\)\s+\d+.\d+%/
+    artifacts:
+        reports:
+          coverage_report:
+            coverage_format: cobertura
+            path: coverage.xml
     needs:
         - generate-api
 
diff --git a/README.md b/README.md
index 73d185e0..fc8564e7 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,8 @@
 # Costaquanta
 
+![Pipeline Status](https://gitlab.example.com/danet/costaquanta/badges/main/pipeline.svg)
+![coverage](https://gitlab.example.com/danet/costaquanta/badges/main/coverage.svg)
+
 This repository is used for development and testing of QKDN software.
 It's use-case is research and development only.
 If you are interested in production grade QKDN software, please feel free to contact us.
diff --git a/justfile b/justfile
index db8ec879..62fdb243 100644
--- a/justfile
+++ b/justfile
@@ -11,7 +11,10 @@ build-api:
     buf generate
 
 test:
-    go test ./...
+    go test -coverprofile=cover.profile ./...
+
+code-coverage: test
+    go tool cover -func cover.profile
 
 lint:
     docker run --rm -t -v $(pwd):/app -w /app \
-- 
GitLab