check / check (push) Waiting to run
`vaultik snapshot files <snapshot-id> [path] [--json]` downloads and decrypts the snapshot database, as restore does, and prints mode, size, modification time and path for every file at or under the path. A path that matches nothing is an error. It needs the private key. The mode is in Go's file-mode notation, which the README spells out. Named `files` because `ls` is already the alias of `snapshot list`. The missing-key error no longer says "for restore", since this command and deep verify return it too. The README opening now states the private-key rule first. Model: opus-5-5
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package cli //nolint:testpackage // shares runEntry and the backup config helpers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"sneak.berlin/go/vaultik/internal/vaultik"
|
|
)
|
|
|
|
// cmdFiles is the word of `snapshot files`, used to build argument
|
|
// vectors below.
|
|
const cmdFiles = "files"
|
|
|
|
// TestEntrySnapshotFilesListsOnlyThePath backs up two files and runs
|
|
// `snapshot files` with the snapshot ID and the path of one of them,
|
|
// which must be the only file listed.
|
|
//
|
|
//nolint:paralleltest // replaces os.Args, os.Stdout, os.Stderr and the xdg globals
|
|
func TestEntrySnapshotFilesListsOnlyThePath(t *testing.T) {
|
|
configPath, _ := writeBackupConfigWithPrivateKey(t)
|
|
|
|
// writeBackupConfig puts file.txt in the source directory beside the
|
|
// config file.
|
|
sourceDir := filepath.Join(filepath.Dir(configPath), "source")
|
|
listed := filepath.Join(sourceDir, "file.txt")
|
|
|
|
require.NoError(t, os.WriteFile(
|
|
filepath.Join(sourceDir, "other.txt"), []byte("other"), 0o600))
|
|
|
|
code, _, stderr := runEntry(t,
|
|
flagConfig, configPath, cmdSnapshot, cmdCreate)
|
|
require.Equal(t, 0, code, stderr)
|
|
|
|
code, stdout, stderr := runEntry(t, flagConfig, configPath, cmdSnapshot,
|
|
cmdFiles, onlySnapshotID(t, configPath), listed, flagJSON)
|
|
require.Equal(t, 0, code, stderr)
|
|
|
|
var entries []vaultik.ListedFile
|
|
|
|
require.NoError(t, json.Unmarshal([]byte(stdout), &entries))
|
|
require.Len(t, entries, 1, "only the path given may be listed")
|
|
assert.Equal(t, listed, entries[0].Path)
|
|
}
|