Skip to content

Commit e5e6330

Browse files
Fixed code review comments.
Signed-off-by: naveensrinivasan <[email protected]>
1 parent cff9cd8 commit e5e6330

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ unit-test: ## Runs all unit tests.
3636
coverage: ## Runs all unit tests and generates a coverage report.
3737
echo "Ensuring the code coverage is met"
3838
go mod vendor
39-
go test -mod=vendor -coverprofile=coverage ./... | THRESHOLD_FILE=$(COVERAGE_THRESHOLD_FILE) COVERAGE_PERCENTAGE=$(TEST_COVERAGE_PERCENTAGE) go run ./hack/codecoverage/main.go
39+
go test -mod=vendor -coverprofile=coverage ./... | go run ./hack/codecoverage/main.go $(COVERAGE_THRESHOLD_FILE) $(TEST_COVERAGE_PERCENTAGE)
4040

4141
## Linters
4242
#####################################################################

hack/codecoverage/main.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ import (
2323
)
2424

2525
func main() {
26-
thresholdFile := os.Getenv("THRESHOLD_FILE")
26+
if len(os.Args) != 3 {
27+
log.Fatal("Usage: <threshold-file> <coverage-percent>")
28+
}
29+
thresholdFile := os.Args[1]
2730
if thresholdFile == "" {
28-
log.Fatalf("THRESHOLD_FILE environment variable is not set")
31+
log.Fatalf("The thresholdfile cannot be empty.")
2932
}
3033
thresholdMap, err := parseCoverageThreshold(thresholdFile)
3134
if err != nil {
3235
log.Fatalf("Error parsing threshold file: %v", err)
3336
}
34-
coveragePercentage := os.Getenv("COVERAGE_PERCENTAGE")
37+
coveragePercentage := os.Args[2]
3538
if coveragePercentage == "" {
36-
log.Fatalf("COVERAGE_PERCENTAGE environment variable is not set")
39+
log.Fatalf("The coverage percentage cannot be empty.")
3740
}
38-
coveragePercentageFloat, err := strconv.ParseFloat(coveragePercentage, 32)
41+
coveragePercentageFloat, err := strconv.ParseFloat(coveragePercentage, 64)
3942
if err != nil {
4043
log.Fatalf("Error parsing coverage percentage: %v", err)
4144
}
@@ -48,19 +51,20 @@ func main() {
4851
if len(parts) < 5 {
4952
continue
5053
}
51-
percentage, err := strconv.ParseFloat(strings.Trim(parts[4], "%"), 32)
54+
percentage, err := strconv.ParseFloat(strings.Trim(parts[4], "%"), 64)
5255
if err != nil {
5356
log.Fatalf("invalid line: %s", line)
5457
}
5558
pack := parts[1]
56-
if val, ok := thresholdMap[pack]; !ok {
57-
if float32(int(percentage*100)/100) < float32(int(coveragePercentageFloat*100)/100) {
58-
log.Fatalf("coverage for %s is below threshold: %f < %f", pack, percentage, coveragePercentageFloat)
59-
}
60-
} else {
61-
if float32(int(percentage*100)/100) < float32(int(val*100)/100) {
59+
if val, ok := thresholdMap[pack]; ok {
60+
if percentage < val {
6261
log.Fatalf("coverage for %s is below threshold: %f < %f", pack, percentage, val)
6362
}
63+
continue
64+
}
65+
// if the package is not in the threshold map, then we check if the coverage is below the threshold
66+
if percentage < coveragePercentageFloat {
67+
log.Fatalf("coverage for %s is below threshold: %f < %f", pack, percentage, coveragePercentageFloat)
6468
}
6569
}
6670
}

0 commit comments

Comments
 (0)