Files
kopia/cli/storage_inmemory_test.go
Shikhar Mall aa5e4cfb33 refactor(cli): An in-memory storage mock setup for CLI tests (#1697)
* refactor cli tests to allow the use of in-memory mock

* use in-memory repo for set-parameters cli tests

* move inmemory storage provider into test package

Co-authored-by: Shikhar Mall <shikhar@kasten.io>
2022-02-01 10:29:13 -08:00

30 lines
823 B
Go

package cli_test
import (
"context"
"github.com/alecthomas/kingpin"
"github.com/kopia/kopia/cli"
"github.com/kopia/kopia/internal/repotesting"
"github.com/kopia/kopia/repo/blob"
)
// storageInMemoryFlags is in-memory storage initialization flags for cli
// setup.
type storageInMemoryFlags struct {
options repotesting.ReconnectableStorageOptions
}
func (c *storageInMemoryFlags) Setup(_ cli.StorageProviderServices, cmd *kingpin.CmdClause) {
cmd.Flag("uuid", "UUID of the reconnectable in-memory storage").Required().StringVar(&c.options.UUID)
}
func (c *storageInMemoryFlags) Connect(ctx context.Context, isCreate bool, _ int) (blob.Storage, error) {
// nolint:wrapcheck
return blob.NewStorage(ctx, blob.ConnectionInfo{
Type: repotesting.ReconnectableStorageType,
Config: &c.options,
}, isCreate)
}