github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/syz-cluster/pkg/db/util_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 "context" 8 "testing" 9 "time" 10 11 "cloud.google.com/go/spanner" 12 "github.com/google/syzkaller/syz-cluster/pkg/api" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 type dummyTestData struct { 17 t *testing.T 18 ctx context.Context 19 client *spanner.Client 20 } 21 22 func (d *dummyTestData) addSessionTest(session *Session, names ...string) { 23 testsRepo := NewSessionTestRepository(d.client) 24 for _, name := range names { 25 err := testsRepo.InsertOrUpdate(d.ctx, &SessionTest{ 26 SessionID: session.ID, 27 TestName: name, 28 Result: api.TestPassed, 29 }, nil) 30 assert.NoError(d.t, err) 31 } 32 } 33 34 func (d *dummyTestData) dummySeries() *Series { 35 seriesRepo := NewSeriesRepository(d.client) 36 series := &Series{ExtID: "series-ext-id"} 37 err := seriesRepo.Insert(d.ctx, series, nil) 38 assert.NoError(d.t, err) 39 return series 40 } 41 42 func (d *dummyTestData) dummySession(series *Series) *Session { 43 sessionRepo := NewSessionRepository(d.client) 44 session := &Session{ 45 SeriesID: series.ID, 46 CreatedAt: time.Now(), 47 } 48 err := sessionRepo.Insert(d.ctx, session) 49 assert.NoError(d.t, err) 50 return session 51 } 52 53 func (d *dummyTestData) startSession(session *Session) { 54 sessionRepo := NewSessionRepository(d.client) 55 err := sessionRepo.Start(d.ctx, session.ID) 56 assert.NoError(d.t, err) 57 } 58 59 func (d *dummyTestData) finishSession(session *Session) { 60 sessionRepo := NewSessionRepository(d.client) 61 err := sessionRepo.Update(d.ctx, session.ID, func(session *Session) error { 62 session.SetFinishedAt(time.Now()) 63 return nil 64 }) 65 assert.NoError(d.t, err) 66 } 67 68 func (d *dummyTestData) addFinding(session *Session, title, test string) *Finding { 69 findingRepo := NewFindingRepository(d.client) 70 finding := &Finding{ 71 SessionID: session.ID, 72 Title: title, 73 TestName: test, 74 } 75 assert.NoError(d.t, findingRepo.mustStore(d.ctx, finding)) 76 return finding 77 } 78 79 func (d *dummyTestData) invalidateFinding(f *Finding) { 80 findingRepo := NewFindingRepository(d.client) 81 assert.NoError(d.t, findingRepo.Update(d.ctx, f.ID, func(f *Finding) error { 82 f.SetInvalidatedAt(time.Now()) 83 return nil 84 })) 85 }