chore(go): harden coverage-gate file input handling
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -86,3 +87,33 @@ func TestEvaluateCoverage_NoStatementsPasses(t *testing.T) {
|
||||
t.Fatalf("expected pass for no-statement package, got %+v", results[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadPolicy_RejectsNonJSONPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tmp := t.TempDir()
|
||||
policyPath := filepath.Join(tmp, "policy.yaml")
|
||||
if err := os.WriteFile(policyPath, []byte("minimum_statement_coverage: 80\n"), 0600); err != nil {
|
||||
t.Fatalf("write policy file: %v", err)
|
||||
}
|
||||
|
||||
_, err := LoadPolicy(policyPath)
|
||||
if err == nil {
|
||||
t.Fatal("expected LoadPolicy to fail for non-json extension")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "invalid policy file extension") {
|
||||
t.Fatalf("expected extension error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCoverProfile_RejectsDirectoryPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := ParseCoverProfile(t.TempDir(), Policy{MinimumStatementCoverage: 80})
|
||||
if err == nil {
|
||||
t.Fatal("expected ParseCoverProfile to fail for directory path")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "coverage profile path must be a file") {
|
||||
t.Fatalf("expected directory path error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user