package storage_test import ( "context" "errors" "testing" "sneak.berlin/go/vaultik/internal/storage" ) // The rclone backend is a thin adapter over the rclone library: it turns a // (remote, path) pair into rclone's "remote:path" string, hands it to // rclone, and maps rclone's own results back to the Storer interface. What // can be tested in-process, without a configured remote or network, is that // adapter layer — how the arguments are shaped and how construction errors // are reported. The data-plane operations (Put/Get/List/Delete) are rclone's // own, exercised against a real provider (drive, s3-via-rclone, ...), which // needs a configured remote with credentials and network access and so is // out of reach of a unit test. The shared Storer conformance suite therefore // runs against the in-process file and s3 backends; the rclone backend // inherits that contract once a remote is configured. // // These tests use rclone's ":local:" on-the-fly backend, which addresses the // local filesystem directly without any configured remote, so construction // runs entirely in-process. // TestNewRcloneStorerConstruction checks that a valid remote constructs a // backend and that Info() reports the shaped "remote:path" location. // //nolint:paralleltest // NewRcloneStorer installs the process-global rclone config func TestNewRcloneStorerConstruction(t *testing.T) { dir := t.TempDir() s, err := storage.NewRcloneStorer(context.Background(), ":local", dir) if err != nil { t.Fatalf("NewRcloneStorer: %v", err) } // Info().Location is the "remote:path" string the adapter builds from // its two arguments, so asserting it confirms the argument shaping. want := ":local:" + dir if got := s.Info().Location; got != want { t.Errorf("Info().Location = %q, want %q", got, want) } } // TestNewRcloneStorerUnknownRemote checks that a remote that is not in the // rclone config fails construction with the ErrRemoteNotFound sentinel, // rather than silently returning a backend pointed nowhere. // //nolint:paralleltest // NewRcloneStorer installs the process-global rclone config func TestNewRcloneStorerUnknownRemote(t *testing.T) { _, err := storage.NewRcloneStorer( context.Background(), "vaultik-no-such-remote", "path") if !errors.Is(err, storage.ErrRemoteNotFound) { t.Errorf("NewRcloneStorer error = %v, want ErrRemoteNotFound", err) } }