mirror of
https://github.com/restic/restic.git
synced 2026-06-06 17:09:44 +00:00
restic: move test helpers and drop unused JSONUnpackedLoader
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user