github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/email/action_test.go (about)

     1  // Copyright 2023 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  package email
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/google/syzkaller/dashboard/dashapi"
    10  )
    11  
    12  func TestMessageActions(t *testing.T) {
    13  	tests := []struct {
    14  		name      string
    15  		msg       *Email
    16  		msgType   dashapi.DiscussionType
    17  		oldThread *OldThreadInfo
    18  		result    MessageAction
    19  	}{
    20  		{
    21  			name:      "plain new thread",
    22  			msg:       &Email{},
    23  			msgType:   dashapi.DiscussionReport,
    24  			oldThread: nil,
    25  			result:    ActionNewThread,
    26  		},
    27  		{
    28  			name: "plain reply to a report",
    29  			msg: &Email{
    30  				InReplyTo: "<abcd>",
    31  			},
    32  			msgType: dashapi.DiscussionReport,
    33  			oldThread: &OldThreadInfo{
    34  				ThreadType: dashapi.DiscussionReport,
    35  			},
    36  			result: ActionAppend,
    37  		},
    38  		{
    39  			name: "plain reply to a patch",
    40  			msg: &Email{
    41  				InReplyTo: "<abcd>",
    42  			},
    43  			msgType: dashapi.DiscussionReport,
    44  			oldThread: &OldThreadInfo{
    45  				ThreadType: dashapi.DiscussionPatch,
    46  			},
    47  			result: ActionAppend,
    48  		},
    49  		{
    50  			name: "sudden syzbot reply",
    51  			msg: &Email{
    52  				OwnEmail:  true,
    53  				InReplyTo: "<abcd>",
    54  			},
    55  			msgType:   dashapi.DiscussionReport,
    56  			oldThread: nil,
    57  			result:    ActionIgnore,
    58  		},
    59  		{
    60  			name: "legit subdiscussion",
    61  			msg: &Email{
    62  				InReplyTo: "<abcd>",
    63  			},
    64  			msgType:   dashapi.DiscussionReport,
    65  			oldThread: nil,
    66  			result:    ActionNewThread,
    67  		},
    68  		{
    69  			name: "patch reply to report",
    70  			msg: &Email{
    71  				InReplyTo: "<abcd>",
    72  			},
    73  			msgType: dashapi.DiscussionPatch,
    74  			oldThread: &OldThreadInfo{
    75  				ThreadType: dashapi.DiscussionReport,
    76  			},
    77  			result: ActionNewThread,
    78  		},
    79  	}
    80  	for _, _test := range tests {
    81  		test := _test
    82  		t.Run(test.name, func(tt *testing.T) {
    83  			got := NewMessageAction(test.msg, test.msgType, test.oldThread)
    84  			if got != test.result {
    85  				t.Fatalf("wanted %v, got %v", test.result, got)
    86  			}
    87  		})
    88  	}
    89  }