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
|
// Copyright 2025 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 db
import (
"context"
"testing"
"time"
"cloud.google.com/go/spanner"
"github.com/google/syzkaller/syz-cluster/pkg/api"
"github.com/stretchr/testify/assert"
)
type dummyTestData struct {
t *testing.T
ctx context.Context
client *spanner.Client
}
func (d *dummyTestData) addSessionTest(session *Session, names ...string) {
testsRepo := NewSessionTestRepository(d.client)
for _, name := range names {
err := testsRepo.InsertOrUpdate(d.ctx, &SessionTest{
SessionID: session.ID,
TestName: name,
Result: api.TestPassed,
}, nil)
assert.NoError(d.t, err)
}
}
func (d *dummyTestData) dummySeries() *Series {
seriesRepo := NewSeriesRepository(d.client)
series := &Series{ExtID: "series-ext-id"}
err := seriesRepo.Insert(d.ctx, series, nil)
assert.NoError(d.t, err)
return series
}
func (d *dummyTestData) dummySession(series *Series) *Session {
sessionRepo := NewSessionRepository(d.client)
session := &Session{
SeriesID: series.ID,
CreatedAt: time.Now(),
}
err := sessionRepo.Insert(d.ctx, session)
assert.NoError(d.t, err)
return session
}
func (d *dummyTestData) startSession(session *Session) {
sessionRepo := NewSessionRepository(d.client)
err := sessionRepo.Start(d.ctx, session.ID)
assert.NoError(d.t, err)
}
func (d *dummyTestData) finishSession(session *Session) {
sessionRepo := NewSessionRepository(d.client)
err := sessionRepo.Update(d.ctx, session.ID, func(session *Session) error {
session.SetFinishedAt(time.Now())
return nil
})
assert.NoError(d.t, err)
}
func (d *dummyTestData) addFinding(session *Session, title, test string) *Finding {
findingRepo := NewFindingRepository(d.client)
finding := &Finding{
SessionID: session.ID,
Title: title,
TestName: test,
}
assert.NoError(d.t, findingRepo.mustStore(d.ctx, finding))
return finding
}
func (d *dummyTestData) invalidateFinding(f *Finding) {
findingRepo := NewFindingRepository(d.client)
assert.NoError(d.t, findingRepo.Update(d.ctx, f.ID, func(f *Finding) error {
f.SetInvalidatedAt(time.Now())
return nil
}))
}
|