1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright 2025 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package report
import (
"encoding/json"
"flag"
"os"
"path/filepath"
"strings"
"testing"
"github.com/google/syzkaller/syz-cluster/pkg/api"
"github.com/google/syzkaller/syz-cluster/pkg/app"
"github.com/stretchr/testify/assert"
)
var flagWrite = flag.Bool("write", false, "overwrite out.txt files")
func TestRender(t *testing.T) {
config := &app.EmailConfig{
Name: "syzbot",
DocsLink: "http://docs/link",
CreditEmail: "credit@email.com",
SupportEmail: "support@email.com",
}
flag.Parse()
basePath := "testdata"
files, err := os.ReadDir(basePath)
if err != nil {
t.Fatal(err)
}
for _, file := range files {
if filepath.Ext(file.Name()) != ".json" {
continue
}
fullName := file.Name()
name := strings.TrimSuffix(fullName, ".in.json")
t.Run(name, func(t *testing.T) {
t.Parallel()
inPath := filepath.Join(basePath, fullName)
inputData, err := os.ReadFile(inPath)
assert.NoError(t, err)
var report api.SessionReport
err = json.Unmarshal(inputData, &report)
assert.NoError(t, err)
for _, value := range []bool{false, true} {
report.Moderation = value
suffix := "upstream"
if value {
suffix = "moderation"
}
t.Run(suffix, func(t *testing.T) {
output, err := Render(&report, config)
assert.NoError(t, err)
outPath := filepath.Join(basePath, name+"."+suffix+".txt")
if *flagWrite {
err := os.WriteFile(outPath, output, 0644)
assert.NoError(t, err)
} else {
expected, err := os.ReadFile(outPath)
assert.NoError(t, err)
assert.Equal(t, string(expected), string(output))
}
})
}
})
}
}
|