From 5d17667bb6ecde104eff665d3c096ac2b7984648 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 12 Apr 2023 11:17:35 +0200 Subject: all: refactor discussion processing code Now that too much logic seems to be duplicated in tools/syz-lore and dahsboard/app/discussion.go, it's time to refactor the code. Factor out the code that decides whether an incoming email message should start a new thread or be appended to the previous one. Restructure pkg/email/lore so that email processing matches the one-by-one approach of reporting_email.go. --- pkg/email/lore/parse_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'pkg/email/lore/parse_test.go') diff --git a/pkg/email/lore/parse_test.go b/pkg/email/lore/parse_test.go index 86e2b51b7..2343a7c26 100644 --- a/pkg/email/lore/parse_test.go +++ b/pkg/email/lore/parse_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/google/syzkaller/dashboard/dashapi" "github.com/google/syzkaller/pkg/email" ) @@ -112,6 +113,7 @@ Bug report`, "": { Subject: "Thread A", MessageID: "", + Type: dashapi.DiscussionReport, Messages: []*email.Email{ { MessageID: "", @@ -144,6 +146,7 @@ Bug report`, "": { Subject: "[syzbot] Some bug", MessageID: "", + Type: dashapi.DiscussionReport, BugIDs: []string{"4564456"}, Messages: []*email.Email{ { @@ -180,6 +183,7 @@ Bug report`, "": { Subject: "[PATCH] Some bug fixed", MessageID: "", + Type: dashapi.DiscussionPatch, BugIDs: []string{"12345"}, Messages: []*email.Email{ { @@ -196,6 +200,7 @@ Bug report`, "": { Subject: "[syzbot] Some bug 2", MessageID: "", + Type: dashapi.DiscussionReport, BugIDs: []string{"4564456"}, Messages: []*email.Email{ { @@ -244,3 +249,35 @@ Bug report`, t.Fatalf("Expected %d threads, got %d", len(expected), len(threads)) } } + +func TestDiscussionType(t *testing.T) { + tests := []struct { + msg *email.Email + ret dashapi.DiscussionType + }{ + { + msg: &email.Email{ + Subject: "[PATCH] Bla-bla", + }, + ret: dashapi.DiscussionPatch, + }, + { + msg: &email.Email{ + Subject: "[syzbot] Monthly ext4 report", + }, + ret: dashapi.DiscussionReminder, + }, + { + msg: &email.Email{ + Subject: "[syzbot] WARNING in abcd", + }, + ret: dashapi.DiscussionReport, + }, + } + for _, test := range tests { + got := DiscussionType(test.msg) + if got != test.ret { + t.Fatalf("expected %v got %v for %v", test.ret, got, test.msg) + } + } +} -- cgit mrf-deployment