@@ -5,33 +5,14 @@ import (
55 "context"
66 "database/sql"
77 "encoding/json"
8- "path/filepath"
98 "strings"
109 "testing"
1110
12- "github.com/radimsem/remindb/pkg/store "
11+ "github.com/radimsem/remindb/internal/testutil "
1312)
1413
15- func newCleanStore (t * testing.T ) (* store.Store , string ) {
16- t .Helper ()
17-
18- dir := t .TempDir ()
19- path := filepath .Join (dir , "doctor.db" )
20-
21- st , err := store .Open (path )
22- if err != nil {
23- t .Fatalf ("Open: %v" , err )
24- }
25- t .Cleanup (func () { _ = st .Close () })
26-
27- if err := st .Migrate (context .Background ()); err != nil {
28- t .Fatalf ("Migrate: %v" , err )
29- }
30- return st , path
31- }
32-
3314func TestRunCleanDB (t * testing.T ) {
34- st , _ := newCleanStore (t )
15+ st , _ := testutil . OpenTestDBFile (t )
3516
3617 report := Run (context .Background (), st )
3718
@@ -66,7 +47,7 @@ func TestRunCleanDB(t *testing.T) {
6647}
6748
6849func TestHealFixesBrokenFTS (t * testing.T ) {
69- st , path := newCleanStore (t )
50+ st , path := testutil . OpenTestDBFile (t )
7051
7152 insertSampleNodes (t , path )
7253
@@ -99,7 +80,7 @@ func TestHealFixesBrokenFTS(t *testing.T) {
9980}
10081
10182func TestHealIsIdempotent (t * testing.T ) {
102- st , _ := newCleanStore (t )
83+ st , _ := testutil . OpenTestDBFile (t )
10384
10485 first := Heal (context .Background (), st )
10586 second := Heal (context .Background (), st )
@@ -116,7 +97,7 @@ func TestHealIsIdempotent(t *testing.T) {
11697}
11798
11899func TestReportJSONShape (t * testing.T ) {
119- st , _ := newCleanStore (t )
100+ st , _ := testutil . OpenTestDBFile (t )
120101
121102 report := Run (context .Background (), st )
122103
@@ -151,7 +132,7 @@ func TestReportJSONShape(t *testing.T) {
151132}
152133
153134func TestReportTextShape (t * testing.T ) {
154- st , _ := newCleanStore (t )
135+ st , _ := testutil . OpenTestDBFile (t )
155136
156137 report := Run (context .Background (), st )
157138
@@ -254,7 +235,7 @@ func TestWriteTextHeader(t *testing.T) {
254235}
255236
256237func TestWriteTextHeaderHealsToHealthy (t * testing.T ) {
257- st , path := newCleanStore (t )
238+ st , path := testutil . OpenTestDBFile (t )
258239
259240 insertSampleNodes (t , path )
260241 if err := breakFTSSync (path ); err != nil {
0 commit comments