check / check (push) Failing after 20m56s
A backup of a directory that holds the local index stored a torn copy of it, its -wal and -shm side files and vaultik.pid, all being written while they were read. The scan now treats these files as excluded, whatever the config says. Their paths come from index_path and the lock directory, with symlinks in their directories resolved the way source paths are. If index_path is itself a symlink, SQLite writes the file it points to, so that file and its side files are skipped too. pidlock now owns the lock directory and the PID file name, so the CLI and the scanner use the same path. database delete now removes the side files database.IndexFiles lists, the -journal file included. Model: opus-5-5
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package cli //nolint:testpackage // sets the unexported rootFlags directly
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"sneak.berlin/go/vaultik/internal/database"
|
|
"sneak.berlin/go/vaultik/internal/vaultik"
|
|
)
|
|
|
|
// TestDatabaseDeleteDeclinedIsError checks that answering anything but
|
|
// "yes" keeps the database and returns ErrNotConfirmed, so the command
|
|
// exits non-zero.
|
|
//
|
|
//nolint:paralleltest // mutates the process-global rootFlags
|
|
func TestDatabaseDeleteDeclinedIsError(t *testing.T) {
|
|
dir := t.TempDir()
|
|
dbPath, cfgPath := seedDatabaseDeleteConfig(t, dir)
|
|
|
|
setRootFlags(t, RootFlags{ConfigPath: cfgPath})
|
|
|
|
var out bytes.Buffer
|
|
|
|
cmd := newDatabaseDeleteCommand()
|
|
cmd.SetOut(&out)
|
|
cmd.SetErr(io.Discard)
|
|
cmd.SetIn(strings.NewReader("no\n"))
|
|
cmd.SetArgs(nil)
|
|
|
|
err := cmd.Execute()
|
|
if !errors.Is(err, vaultik.ErrNotConfirmed) {
|
|
t.Errorf("declined database delete returned %v, want %v",
|
|
err, vaultik.ErrNotConfirmed)
|
|
}
|
|
|
|
_, err = os.Stat(dbPath)
|
|
if err != nil {
|
|
t.Errorf("declined database delete removed the file: %v", err)
|
|
}
|
|
|
|
if !strings.Contains(out.String(), "Aborted.") {
|
|
t.Errorf("declined database delete printed %q, want Aborted.",
|
|
out.String())
|
|
}
|
|
}
|
|
|
|
// TestDatabaseDeleteRemovesSideFiles checks that the side files SQLite
|
|
// keeps beside the database file are deleted with it.
|
|
//
|
|
//nolint:paralleltest // mutates the process-global rootFlags
|
|
func TestDatabaseDeleteRemovesSideFiles(t *testing.T) {
|
|
dir := t.TempDir()
|
|
dbPath, cfgPath := seedDatabaseDeleteConfig(t, dir)
|
|
|
|
indexFiles := database.IndexFiles(dbPath)
|
|
for _, indexFile := range indexFiles {
|
|
seedFile(t, dir, filepath.Base(indexFile), "data")
|
|
}
|
|
|
|
setRootFlags(t, RootFlags{ConfigPath: cfgPath})
|
|
|
|
mustExecute(t, newDatabaseDeleteCommand(), "--force")
|
|
|
|
for _, indexFile := range indexFiles {
|
|
_, err := os.Stat(indexFile)
|
|
if !os.IsNotExist(err) {
|
|
t.Errorf("database delete left %s: stat err = %v", indexFile, err)
|
|
}
|
|
}
|
|
}
|