Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b98822a5ab |
@@ -304,63 +304,6 @@ func TestFileRepositoryMTimeOutsideInt64NanosecondRange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A file already in the index and rewritten within the same second must get
|
|
||||||
// its new nanoseconds stored, through both Create and CreateBatch.
|
|
||||||
func TestFileRepositoryUpsertMTimeInSameSecond(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
db, cleanup := setupTestDB(t)
|
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
repo := database.NewFileRepository(db)
|
|
||||||
|
|
||||||
indexed := time.Date(2026, time.October, 7, 12, 0, 0, 100000000, time.UTC)
|
|
||||||
rewritten := indexed.Add(800 * time.Millisecond)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
upsert func(file *database.File) error
|
|
||||||
}{
|
|
||||||
{"Create", func(file *database.File) error {
|
|
||||||
return repo.Create(ctx, nil, file)
|
|
||||||
}},
|
|
||||||
{"CreateBatch", func(file *database.File) error {
|
|
||||||
return repo.CreateBatch(ctx, nil, []*database.File{file})
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
file := &database.File{
|
|
||||||
ID: types.NewFileID(),
|
|
||||||
Path: types.FilePath("/" + tt.name),
|
|
||||||
MTime: indexed,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := tt.upsert(file)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%s: failed to create file: %v", tt.name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
file.MTime = rewritten
|
|
||||||
|
|
||||||
err = tt.upsert(file)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%s: failed to update file: %v", tt.name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
retrieved, err := repo.GetByPath(ctx, file.Path.String())
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%s: failed to get file: %v", tt.name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !retrieved.MTime.Equal(rewritten) {
|
|
||||||
t.Errorf("%s: mtime got %v, want %v",
|
|
||||||
tt.name, retrieved.MTime, rewritten)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFileRepositoryTransaction(t *testing.T) {
|
func TestFileRepositoryTransaction(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user