MCPcopy Index your code
hub / github.com/devploit/nomore403 / TestOutputWriter_JSONL

Function TestOutputWriter_JSONL

cmd/output_test.go:121–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func 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}

Callers

nothing calls this directly

Calls 3

initOutputWriterFunction · 0.85
writeResultToOutputFunction · 0.85
closeOutputWriterFunction · 0.85

Tested by

no test coverage detected