(t *testing.T)
| 82 | } |
| 83 | |
| 84 | func TestJSONFormatter_WithIssues(t *testing.T) { |
| 85 | linter := newDefaultLinter(t) |
| 86 | result, err := linter.ParseAndLint("invalid commit no type") |
| 87 | if err != nil { |
| 88 | t.Fatal(err) |
| 89 | } |
| 90 | f := &formatter.JSONFormatter{} |
| 91 | out, fErr := f.Format(result) |
| 92 | if fErr != nil { |
| 93 | t.Fatal(fErr) |
| 94 | } |
| 95 | var parsed map[string]interface{} |
| 96 | if jErr := json.Unmarshal([]byte(out), &parsed); jErr != nil { |
| 97 | t.Fatalf("invalid JSON output: %v", jErr) |
| 98 | } |
| 99 | issues, ok := parsed["issues"].([]interface{}) |
| 100 | if !ok { |
| 101 | t.Fatal("expected 'issues' array in JSON") |
| 102 | } |
| 103 | if len(issues) == 0 { |
| 104 | t.Error("expected at least one issue for invalid commit") |
| 105 | } |
| 106 | // Verify each issue has mandatory fields |
| 107 | for i, raw := range issues { |
| 108 | entry, ok := raw.(map[string]interface{}) |
| 109 | if !ok { |
| 110 | t.Fatalf("issue[%d] is not a map", i) |
| 111 | } |
| 112 | for _, field := range []string{"name", "severity", "description"} { |
| 113 | if _, exists := entry[field]; !exists { |
| 114 | t.Errorf("issue[%d] missing field %q", i, field) |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func TestJSONFormatter_InputField(t *testing.T) { |
| 121 | linter := newDefaultLinter(t) |
nothing calls this directly
no test coverage detected