MCPcopy Create free account
hub / github.com/chainreactors/spray / TestFormatParsesResultFile

Function TestFormatParsesResultFile

core/format_test.go:13–39  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestFormatParsesResultFile(t *testing.T) {
14 dir := t.TempDir()
15 input := filepath.Join(dir, "results.json")
16
17 content := `{"url":"http://127.0.0.1:80","host":"127.0.0.1","title":"home","status":200}
18`
19 if err := os.WriteFile(input, []byte(content), 0o644); err != nil {
20 t.Fatal(err)
21 }
22
23 var out bytes.Buffer
24 oldLog := logs.Log
25 logs.Log = logs.NewLogger(oldLog.Level)
26 logs.Log.SetOutput(&out)
27 defer func() {
28 logs.Log = oldLog
29 }()
30
31 opt := Option{}
32 opt.Format = input
33 opt.OutputProbe = "url,title"
34 Format(opt)
35
36 if got := strings.TrimSpace(out.String()); got != "http://127.0.0.1:80\thome" {
37 t.Fatalf("unexpected formatted output: got %q", got)
38 }
39}

Callers

nothing calls this directly

Calls 2

FormatFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected