package vaultik_test import ( "context" "maps" "path/filepath" "testing" "github.com/spf13/afero" "github.com/stretchr/testify/require" "sneak.berlin/go/vaultik/internal/config" "sneak.berlin/go/vaultik/internal/database" "sneak.berlin/go/vaultik/internal/log" "sneak.berlin/go/vaultik/internal/storage" "sneak.berlin/go/vaultik/internal/vaultik" ) // A backup without --cron runs the progress reporter while one scanner // scans each path of the snapshot in turn. See // https://git.eeqj.de/sneak/vaultik/issues/253. func TestBackupWithoutCronOfTwoPathSnapshotRestoresBothPaths(t *testing.T) { log.Initialize(log.Config{}) t.Parallel() const snapshotName = "data" fs := afero.NewOsFs() tempDir := t.TempDir() firstDir := filepath.Join(tempDir, "first") secondDir := filepath.Join(tempDir, "second") storeDir := filepath.Join(tempDir, "remote") restoreDir := filepath.Join(tempDir, "restored") dbPath := filepath.Join(tempDir, "index.sqlite") ctx := context.Background() files := writeFaultSourceTree(t, fs, firstDir) maps.Copy(files, writeFaultSourceTree(t, fs, secondDir)) cfg := faultTestConfig() cfg.IndexPath = dbPath cfg.ChunkSize = config.Size(faultChunkSize) cfg.Snapshots = map[string]config.SnapshotConfig{ snapshotName: {Paths: []string{firstDir, secondDir}}, } store, err := storage.NewFileStorer(storeDir) require.NoError(t, err) db, err := database.New(ctx, dbPath) require.NoError(t, err) repos := database.NewRepositories(db) v := newBackupVaultik(ctx, cfg, store, repos, db, fs) require.NoError(t, v.CreateSnapshot(&vaultik.SnapshotCreateOptions{ Snapshots: []string{snapshotName}, })) id := localSnapshotID(ctx, t, repos, snapshotName) require.NoError(t, db.Close()) reader := newReaderVaultik(ctx, cfg, store, nil, fs) require.NoError(t, reader.Restore(&vaultik.RestoreOptions{ SnapshotID: id, TargetDir: restoreDir, Verify: true, })) assertRestoredTree(t, fs, restoreDir, files) }