github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/syz-cluster/pkg/db/report_reply_repo_test.go (about)

     1  // Copyright 2025 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 db
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  	"time"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestReportReplyRepository(t *testing.T) {
    15  	client, ctx := NewTransientDB(t)
    16  	dtd := &dummyTestData{t, ctx, client}
    17  	session := dtd.dummySession(dtd.dummySeries())
    18  
    19  	reportRepo := NewReportRepository(client)
    20  	report := &SessionReport{SessionID: session.ID, Reporter: dummyReporter}
    21  	err := reportRepo.Insert(ctx, report)
    22  	assert.NoError(t, err)
    23  
    24  	replyRepo := NewReportReplyRepository(client)
    25  	baseTime := time.Now()
    26  	for i := 0; i < 2; i++ {
    27  		err = replyRepo.Insert(ctx, &ReportReply{
    28  			MessageID: fmt.Sprintf("message-id-%d", i),
    29  			ReportID:  report.ID,
    30  			Time:      baseTime.Add(time.Duration(i) * time.Second),
    31  		})
    32  		assert.NoError(t, err)
    33  	}
    34  
    35  	t.Run("insert-dup-reply", func(t *testing.T) {
    36  		err := replyRepo.Insert(ctx, &ReportReply{
    37  			MessageID: "message-id-0",
    38  			ReportID:  report.ID,
    39  			Time:      time.Now(),
    40  		})
    41  		assert.Error(t, ErrReportReplyExists, err)
    42  	})
    43  
    44  	t.Run("last-report", func(t *testing.T) {
    45  		reply, err := replyRepo.LastForReporter(ctx, dummyReporter)
    46  		assert.NoError(t, err)
    47  		assert.Equal(t, "message-id-1", reply.MessageID)
    48  	})
    49  
    50  	t.Run("last-report-unknown", func(t *testing.T) {
    51  		reply, err := replyRepo.LastForReporter(ctx, "unknown-reporter")
    52  		assert.NoError(t, err)
    53  		assert.Nil(t, reply)
    54  	})
    55  
    56  	t.Run("find-by-parent", func(t *testing.T) {
    57  		reportID, err := replyRepo.FindParentReportID(ctx, dummyReporter, "message-id-0")
    58  		assert.NoError(t, err)
    59  		assert.Equal(t, report.ID, reportID)
    60  	})
    61  }