From a20203e53ffc1c7bd43f7bbab07d8f9967113aeb Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 4 Jun 2026 20:00:03 +0200 Subject: [PATCH] restic: move test helpers and drop unused JSONUnpackedLoader --- internal/restic/backend_find.go | 4 ++-- internal/restic/blob.go | 4 ---- internal/restic/config.go | 5 ----- internal/restic/id.go | 13 ------------- internal/restic/testing.go | 17 +++++++++++++++++ 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/internal/restic/backend_find.go b/internal/restic/backend_find.go index 2f00595c4..1f9700cde 100644 --- a/internal/restic/backend_find.go +++ b/internal/restic/backend_find.go @@ -24,13 +24,13 @@ func (e *NoIDByPrefixError) Error() string { // Find loads the list of all files of type t and searches for names which // start with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. // If more than one is found, nil and ErrMultipleIDMatches is returned. -func Find(ctx context.Context, be Lister, t FileType, prefix string) (ID, error) { +func Find(ctx context.Context, repo Lister, t FileType, prefix string) (ID, error) { match := ID{} ctx, cancel := context.WithCancel(ctx) defer cancel() - err := be.List(ctx, t, func(id ID, _ int64) error { + err := repo.List(ctx, t, func(id ID, _ int64) error { name := id.String() if len(name) >= len(prefix) && prefix == name[:len(prefix)] { if match.IsNull() { diff --git a/internal/restic/blob.go b/internal/restic/blob.go index 432c91db1..ba9277aac 100644 --- a/internal/restic/blob.go +++ b/internal/restic/blob.go @@ -57,10 +57,6 @@ func (h BlobHandle) String() string { return fmt.Sprintf("<%s/%s>", h.Type, h.ID.Str()) } -func NewRandomBlobHandle() BlobHandle { - return BlobHandle{ID: NewRandomID(), Type: DataBlob} -} - // BlobType specifies what a blob stored in a pack is. type BlobType uint8 diff --git a/internal/restic/config.go b/internal/restic/config.go index 264792e11..8af09c908 100644 --- a/internal/restic/config.go +++ b/internal/restic/config.go @@ -26,11 +26,6 @@ const MaxRepoVersion = 2 // is newly created with Init(). const StableRepoVersion = 2 -// JSONUnpackedLoader loads unpacked JSON. -type JSONUnpackedLoader interface { - LoadJSONUnpacked(context.Context, FileType, ID, interface{}) error -} - // CreateConfig creates a config file with a randomly selected polynomial and // ID. func CreateConfig(version uint) (Config, error) { diff --git a/internal/restic/id.go b/internal/restic/id.go index 0742cd6f1..975148283 100644 --- a/internal/restic/id.go +++ b/internal/restic/id.go @@ -1,11 +1,9 @@ package restic import ( - "crypto/rand" "crypto/sha256" "encoding/hex" "fmt" - "io" ) // Hash returns the ID for data. @@ -40,17 +38,6 @@ func (id ID) String() string { return hex.EncodeToString(id[:]) } -// NewRandomID returns a randomly generated ID. When reading from rand fails, -// the function panics. -func NewRandomID() ID { - id := ID{} - _, err := io.ReadFull(rand.Reader, id[:]) - if err != nil { - panic(err) - } - return id -} - const shortStr = 4 // Str returns the shortened string version of id. diff --git a/internal/restic/testing.go b/internal/restic/testing.go index 73e00be70..f52e6e4de 100644 --- a/internal/restic/testing.go +++ b/internal/restic/testing.go @@ -1,7 +1,9 @@ package restic import ( + "crypto/rand" "fmt" + "io" ) // TestParseID parses s as a ID and panics if that fails. @@ -18,3 +20,18 @@ func TestParseID(s string) ID { func TestParseHandle(s string, t BlobType) BlobHandle { return BlobHandle{ID: TestParseID(s), Type: t} } + +func NewRandomBlobHandle() BlobHandle { + return BlobHandle{ID: NewRandomID(), Type: DataBlob} +} + +// NewRandomID returns a randomly generated ID. When reading from rand fails, +// the function panics. +func NewRandomID() ID { + id := ID{} + _, err := io.ReadFull(rand.Reader, id[:]) + if err != nil { + panic(err) + } + return id +}