aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/email/action_test.go
blob: c1ef8507b69f9ea15d6663ee9d60ddf8811a00c9 (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2023 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 email

import (
	"testing"

	"github.com/google/syzkaller/dashboard/dashapi"
)

func TestMessageActions(t *testing.T) {
	tests := []struct {
		name      string
		msg       *Email
		msgType   dashapi.DiscussionType
		oldThread *OldThreadInfo
		result    MessageAction
	}{
		{
			name:      "plain new thread",
			msg:       &Email{},
			msgType:   dashapi.DiscussionReport,
			oldThread: nil,
			result:    ActionNewThread,
		},
		{
			name: "plain reply to a report",
			msg: &Email{
				InReplyTo: "<abcd>",
			},
			msgType: dashapi.DiscussionReport,
			oldThread: &OldThreadInfo{
				ThreadType: dashapi.DiscussionReport,
			},
			result: ActionAppend,
		},
		{
			name: "plain reply to a patch",
			msg: &Email{
				InReplyTo: "<abcd>",
			},
			msgType: dashapi.DiscussionReport,
			oldThread: &OldThreadInfo{
				ThreadType: dashapi.DiscussionPatch,
			},
			result: ActionAppend,
		},
		{
			name: "sudden syzbot reply",
			msg: &Email{
				OwnEmail:  true,
				InReplyTo: "<abcd>",
			},
			msgType:   dashapi.DiscussionReport,
			oldThread: nil,
			result:    ActionIgnore,
		},
		{
			name: "legit subdiscussion",
			msg: &Email{
				InReplyTo: "<abcd>",
			},
			msgType:   dashapi.DiscussionReport,
			oldThread: nil,
			result:    ActionNewThread,
		},
		{
			name: "patch reply to report",
			msg: &Email{
				InReplyTo: "<abcd>",
			},
			msgType: dashapi.DiscussionPatch,
			oldThread: &OldThreadInfo{
				ThreadType: dashapi.DiscussionReport,
			},
			result: ActionNewThread,
		},
	}
	for _, _test := range tests {
		test := _test
		t.Run(test.name, func(tt *testing.T) {
			got := NewMessageAction(test.msg, test.msgType, test.oldThread)
			if got != test.result {
				t.Fatalf("wanted %v, got %v", test.result, got)
			}
		})
	}
}