allow tests to set a specific kopia config dir (#607)
This commit is contained in:
parent
c3c361282d
commit
854635ac24
@ -167,8 +167,6 @@ func (suite *PreparedBackupExchangeIntegrationSuite) SetupSuite() {
|
||||
control.NewOptions(false))
|
||||
require.NoError(t, suite.backupOp.Run(ctx))
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
|
||||
func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeListCmd() {
|
||||
|
||||
@ -2,7 +2,6 @@ package restore_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -45,11 +44,11 @@ func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
|
||||
t := suite.T()
|
||||
_, err := tester.GetRequiredEnvSls(
|
||||
tester.AWSStorageCredEnvs,
|
||||
tester.M365AcctCredEnvs)
|
||||
tester.M365AcctCredEnvs,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// aggregate required details
|
||||
|
||||
suite.acct = tester.NewM365Account(t)
|
||||
suite.st = tester.NewPrefixedS3Storage(t)
|
||||
|
||||
@ -80,8 +79,6 @@ func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
|
||||
control.NewOptions(false))
|
||||
require.NoError(t, suite.backupOp.Run(ctx))
|
||||
require.NoError(t, err)
|
||||
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
|
||||
func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd() {
|
||||
|
||||
@ -2,11 +2,13 @@ package kopia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/kopia/kopia/repo"
|
||||
"github.com/kopia/kopia/repo/blob"
|
||||
"github.com/kopia/kopia/repo/compression"
|
||||
"github.com/kopia/kopia/repo/content"
|
||||
"github.com/kopia/kopia/snapshot"
|
||||
"github.com/kopia/kopia/snapshot/policy"
|
||||
"github.com/pkg/errors"
|
||||
@ -16,7 +18,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultKopiaConfigFilePath = "/tmp/repository.config"
|
||||
defaultKopiaConfigDir = "/tmp/"
|
||||
defaultKopiaConfigFile = "repository.config"
|
||||
defaultCompressor = "s2-default"
|
||||
)
|
||||
|
||||
@ -73,7 +76,7 @@ func (w *conn) Initialize(ctx context.Context) error {
|
||||
|
||||
return w.commonConnect(
|
||||
ctx,
|
||||
defaultKopiaConfigFilePath,
|
||||
cfg.KopiaCfgDir,
|
||||
bst,
|
||||
cfg.CorsoPassword,
|
||||
defaultCompressor,
|
||||
@ -94,7 +97,7 @@ func (w *conn) Connect(ctx context.Context) error {
|
||||
|
||||
return w.commonConnect(
|
||||
ctx,
|
||||
defaultKopiaConfigFilePath,
|
||||
cfg.KopiaCfgDir,
|
||||
bst,
|
||||
cfg.CorsoPassword,
|
||||
defaultCompressor,
|
||||
@ -103,22 +106,35 @@ func (w *conn) Connect(ctx context.Context) error {
|
||||
|
||||
func (w *conn) commonConnect(
|
||||
ctx context.Context,
|
||||
configPath string,
|
||||
configDir string,
|
||||
bst blob.Storage,
|
||||
password, compressor string,
|
||||
) error {
|
||||
var opts *repo.ConnectOptions
|
||||
if len(configDir) > 0 {
|
||||
opts = &repo.ConnectOptions{
|
||||
CachingOptions: content.CachingOptions{
|
||||
CacheDirectory: configDir,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
configDir = defaultKopiaConfigDir
|
||||
}
|
||||
|
||||
cfgFile := filepath.Join(configDir, defaultKopiaConfigFile)
|
||||
|
||||
// todo - issue #75: nil here should be storage.ConnectOptions()
|
||||
if err := repo.Connect(
|
||||
ctx,
|
||||
configPath,
|
||||
cfgFile,
|
||||
bst,
|
||||
password,
|
||||
nil,
|
||||
opts,
|
||||
); err != nil {
|
||||
return errors.Wrap(err, errConnect.Error())
|
||||
}
|
||||
|
||||
if err := w.open(ctx, configPath, password); err != nil {
|
||||
if err := w.open(ctx, cfgFile, password); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@ -15,9 +15,9 @@ import (
|
||||
|
||||
//revive:disable:context-as-argument
|
||||
func openKopiaRepo(t *testing.T, ctx context.Context) (*conn, error) {
|
||||
storage := tester.NewPrefixedS3Storage(t)
|
||||
st := tester.NewPrefixedS3Storage(t)
|
||||
|
||||
k := NewConn(storage)
|
||||
k := NewConn(st)
|
||||
if err := k.Initialize(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -215,3 +215,16 @@ func (suite *WrapperIntegrationSuite) TestCompressorSetOnInitAndConnect() {
|
||||
|
||||
assert.Equal(t, defaultCompressor, string(p.CompressionPolicy.CompressorName))
|
||||
}
|
||||
|
||||
func (suite *WrapperIntegrationSuite) TestInitAndConnWithTempDirectory() {
|
||||
ctx := context.Background()
|
||||
t := suite.T()
|
||||
|
||||
k, err := openKopiaRepo(t, ctx)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, k.Close(ctx))
|
||||
|
||||
// Re-open with Connect.
|
||||
require.NoError(t, k.Connect(ctx))
|
||||
assert.NoError(t, k.Close(ctx))
|
||||
}
|
||||
|
||||
@ -53,6 +53,7 @@ type ModelStoreIntegrationSuite struct {
|
||||
suite.Suite
|
||||
ctx context.Context
|
||||
m *ModelStore
|
||||
cfgDir string
|
||||
}
|
||||
|
||||
func TestModelStoreIntegrationSuite(t *testing.T) {
|
||||
|
||||
@ -452,9 +452,10 @@ func (suite *KopiaIntegrationSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
func (suite *KopiaIntegrationSuite) SetupTest() {
|
||||
t := suite.T()
|
||||
suite.ctx = context.Background()
|
||||
c, err := openKopiaRepo(suite.T(), suite.ctx)
|
||||
require.NoError(suite.T(), err)
|
||||
c, err := openKopiaRepo(t, suite.ctx)
|
||||
require.NoError(t, err)
|
||||
suite.w = &Wrapper{c}
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,9 @@ var AWSStorageCredEnvs = []string{
|
||||
// NewPrefixedS3Storage returns a storage.Storage object initialized with environment
|
||||
// variables used for integration tests that use S3. The prefix for the storage
|
||||
// path will be unique.
|
||||
// Uses t.TempDir() to generate a unique config storage and caching directory for this
|
||||
// test. Suites that need to identify this value can retrieve it again from the common
|
||||
// configs.
|
||||
func NewPrefixedS3Storage(t *testing.T) storage.Storage {
|
||||
now := LogTimeOfTest(t)
|
||||
cfg, err := readTestConfig()
|
||||
@ -32,6 +35,7 @@ func NewPrefixedS3Storage(t *testing.T) storage.Storage {
|
||||
},
|
||||
storage.CommonConfig{
|
||||
Corso: credentials.GetCorso(),
|
||||
KopiaCfgDir: t.TempDir(),
|
||||
},
|
||||
)
|
||||
require.NoError(t, err, "creating storage")
|
||||
|
||||
@ -8,11 +8,14 @@ import (
|
||||
|
||||
type CommonConfig struct {
|
||||
credentials.Corso // requires: CorsoPassword
|
||||
|
||||
KopiaCfgDir string
|
||||
}
|
||||
|
||||
// config key consts
|
||||
const (
|
||||
keyCommonCorsoPassword = "common_corsoPassword"
|
||||
keyCommonKopiaCfgDir = "common_kopiaCfgDir"
|
||||
)
|
||||
|
||||
// StringConfig transforms a commonConfig struct into a plain
|
||||
@ -21,6 +24,7 @@ const (
|
||||
func (c CommonConfig) StringConfig() (map[string]string, error) {
|
||||
cfg := map[string]string{
|
||||
keyCommonCorsoPassword: c.CorsoPassword,
|
||||
keyCommonKopiaCfgDir: c.KopiaCfgDir,
|
||||
}
|
||||
return cfg, c.validate()
|
||||
}
|
||||
@ -30,6 +34,7 @@ func (s Storage) CommonConfig() (CommonConfig, error) {
|
||||
c := CommonConfig{}
|
||||
if len(s.Config) > 0 {
|
||||
c.CorsoPassword = orEmptyString(s.Config[keyCommonCorsoPassword])
|
||||
c.KopiaCfgDir = orEmptyString(s.Config[keyCommonKopiaCfgDir])
|
||||
}
|
||||
return c, c.validate()
|
||||
}
|
||||
@ -39,5 +44,6 @@ func (c CommonConfig) validate() error {
|
||||
if len(c.CorsoPassword) == 0 {
|
||||
return errors.Wrap(errMissingRequired, credentials.CorsoPassword)
|
||||
}
|
||||
// kopiaCfgFilePath is not required
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user