Files
query-orchestration/scripts/tests.yml
T
Jay Brown ab28cf30db Merged in feature/common-metrics (pull request #73)
Add common metrics

* add common metrics

and sample for using

* updates

* attempt integration

* wip

* working

stubs generate

* docs

* comments

* Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/common-metrics

* runner metrics all

* exclude generated

from the coverage

* fix lint

* refactor metrics

* change .gen filename

* new gen

* Merge branch 'main' of bitbucket.org:aarete/query-orchestration into feature/common-metrics

* docs

* main merge

* refactor

* add to generate

* merge main
2025-03-05 16:59:01 +00:00

100 lines
2.6 KiB
YAML

---
# https://taskfile.dev
version: "3"
vars:
COVERAGE_FILE: "{{.OUT_DIR}}/coverage.out"
INTERNAL: "./internal/..."
API: "./api/..."
PKG: "./pkg/..."
CMD: "./cmd/..."
# yamllint disable-line rule:line-length
EXCLUDED_FILES: ".gen.go|internal/serviceconfig/observability/prometheus/generator/main.go"
tasks:
mocks:generate:
cmds:
- rm -rf mocks/*
- mockery
unit:
cmds:
- task: unit:nocoverage
- task: unit:getcoverage
unit:short:
deps:
- mocks:generate
cmds:
- go test -short {{.INTERNAL}} {{.API}} {{.PKG}} {{.CMD}}
unit:nogen:
cmds:
- task: unit:cmd
- task: unit:getcoverage
unit:cmd:
internal: true
cmds:
- mkdir -p {{.OUT_DIR}}
- |
go test {{.INTERNAL}} {{.API}} \
-coverpkg={{.INTERNAL}},{{.API}} \
-coverprofile={{.COVERAGE_FILE}}
unit:nocoverage:
deps:
- mocks:generate
cmds:
- task: unit:cmd
unit:getcoverage:
vars:
TMP_FILE: "{{.OUT_DIR}}/coverage.tmp"
FILTER_COVERAGE_FILE: "{{.OUT_DIR}}/filtered_coverage.out"
cmds:
- |
grep -v -E "{{.EXCLUDED_FILES}}" {{.COVERAGE_FILE}} \
> {{.FILTER_COVERAGE_FILE}}
- go tool cover -func={{.FILTER_COVERAGE_FILE}} > {{.TMP_FILE}}
- |
COVERAGE=$(grep total: {{.TMP_FILE}} \
| awk '{print $3}' | sed 's/%//' | bc)
echo "Coverage Threshold: {{.COVERAGE_THRESHOLD}}%"
echo "Total Coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < {{.COVERAGE_THRESHOLD}}" | bc -l) )); then
echo "❌ Error: Total Coverage below Coverage Threshold"
FAIL=true
fi
echo "Function Coverage Threshold: {{.FUNCTION_COVERAGE_THRESHOLD}}%"
FAIL_FUNC=false
grep -v total: {{.TMP_FILE}} | while read -r line; do
FUNC_COV=$(echo "$line" | awk '{print $3}' | sed 's/%//' | bc)
if (( $(echo "$FUNC_COV < \
{{.FUNCTION_COVERAGE_THRESHOLD}}" | bc -l) )); then
if [ "$FAIL_FUNC" = false ]; then
echo "❌ Error: The following functions have coverage below "\
"{{.FUNCTION_COVERAGE_THRESHOLD}}%:"
FAIL_FUNC=true
FAIL=true
fi
echo "$line"
fi
done
if [ "$FAIL" = true ]; then
exit 1
fi
echo "✅ All coverage checks passed!"
silent: true
endtoend:
cmds:
- task generate
- task docker:build
- task: endtoend:cmd:nocache
endtoend:cmd:nocache:
cmds:
- go test -count=1 -v ./test/...
endtoend:cmd:nobuild:
cmds:
- go test -v ./test/...