github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/syz-cluster/pkg/db/finding_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 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestFindingRepo(t *testing.T) { 13 client, ctx := NewTransientDB(t) 14 seriesRepo := NewSeriesRepository(client) 15 findingRepo := NewFindingRepository(client) 16 dtd := &dummyTestData{t, ctx, client} 17 18 series := &Series{ExtID: "some-series"} 19 err := seriesRepo.Insert(ctx, series, nil) 20 assert.NoError(t, err) 21 22 session := dtd.dummySession(series) 23 24 // Add test steps. 25 dtd.addSessionTest(session, "first", "second") 26 27 // Add findings. 28 toInsert := []*Finding{ 29 { 30 TestName: "first", 31 Title: "A", 32 SessionID: session.ID, 33 }, 34 { 35 TestName: "first", 36 Title: "B", 37 SessionID: session.ID, 38 }, 39 { 40 TestName: "second", 41 Title: "A", 42 SessionID: session.ID, 43 }, 44 } 45 // Insert them all. 46 for _, finding := range toInsert { 47 err := findingRepo.mustStore(ctx, finding) 48 assert.NoError(t, err, "finding=%q", finding) 49 } 50 // Now it should report a duplicate each time. 51 for _, finding := range toInsert { 52 err := findingRepo.mustStore(ctx, finding) 53 assert.ErrorIs(t, err, errFindingExists) 54 } 55 56 list, err := findingRepo.ListForSession(ctx, session.ID, NoLimit) 57 assert.NoError(t, err) 58 assert.Equal(t, toInsert, list) 59 }