(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func TestOutputWriter_JSONL(t *testing.T) { |
| 122 | dir := t.TempDir() |
| 123 | outPath := filepath.Join(dir, "output.jsonl") |
| 124 | |
| 125 | oldJSONL := jsonLines |
| 126 | jsonLines = true |
| 127 | defer func() { jsonLines = oldJSONL }() |
| 128 | |
| 129 | jsonResultsMutex.Lock() |
| 130 | jsonResults = nil |
| 131 | jsonResultsMutex.Unlock() |
| 132 | |
| 133 | if err := initOutputWriter(outPath); err != nil { |
| 134 | t.Fatalf("initOutputWriter: %v", err) |
| 135 | } |
| 136 | |
| 137 | writeResultToOutput(Result{line: "GET /admin", statusCode: 200, contentLength: 1234, score: 88, likelihood: "high"}, "verb-tampering") |
| 138 | writeResultToOutput(Result{line: "X-Original-URL: /", statusCode: 302, contentLength: 12, score: 67, likelihood: "medium"}, "header-confusion") |
| 139 | closeOutputWriter() |
| 140 | |
| 141 | data, err := os.ReadFile(outPath) |
| 142 | if err != nil { |
| 143 | t.Fatalf("read output: %v", err) |
| 144 | } |
| 145 | |
| 146 | lines := strings.Split(strings.TrimSpace(string(data)), "\n") |
| 147 | if len(lines) != 2 { |
| 148 | t.Fatalf("expected 2 jsonl lines, got %d", len(lines)) |
| 149 | } |
| 150 | |
| 151 | var first JSONResult |
| 152 | if err := json.Unmarshal([]byte(lines[0]), &first); err != nil { |
| 153 | t.Fatalf("unmarshal first jsonl line: %v", err) |
| 154 | } |
| 155 | if first.Score != 88 || first.Likelihood != "high" { |
| 156 | t.Fatalf("unexpected first jsonl result: %+v", first) |
| 157 | } |
| 158 | } |
nothing calls this directly
no test coverage detected