41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package storage
|
|
|
|
import "context"
|
|
|
|
// NoopBackend is a deterministic no-op archive/storage adapter.
|
|
type NoopBackend struct{}
|
|
|
|
// Archive returns the requested items as archived with placeholder metadata.
|
|
func (n *NoopBackend) Archive(ctx context.Context, req ArchiveRequest) (ArchiveResult, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return ArchiveResult{}, err
|
|
}
|
|
return ArchiveResult{Archived: append([]ArchiveItem(nil), req.Items...), Metadata: map[string]any{"placeholder": true}}, nil
|
|
}
|
|
|
|
// FakeBackend captures archive requests and returns deterministic responses.
|
|
type FakeBackend struct {
|
|
Requests []ArchiveRequest
|
|
Err error
|
|
Result ArchiveResult
|
|
}
|
|
|
|
// Archive records request and returns configured response.
|
|
func (f *FakeBackend) Archive(ctx context.Context, req ArchiveRequest) (ArchiveResult, error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return ArchiveResult{}, err
|
|
}
|
|
f.Requests = append(f.Requests, req)
|
|
if f.Err != nil {
|
|
return ArchiveResult{}, f.Err
|
|
}
|
|
res := f.Result
|
|
if res.Archived == nil {
|
|
res.Archived = append([]ArchiveItem(nil), req.Items...)
|
|
}
|
|
if res.Metadata == nil {
|
|
res.Metadata = map[string]any{"fake": true}
|
|
}
|
|
return res, nil
|
|
}
|