Skip to content

Commit 1ec8e74

Browse files
committed
fix(repo): Don't use blank path for new repo in tests
Real runs of qri read the config from a path, which sets that path. Most tests use a mem repo. The test TestNewInstanceWithAccessControlPolicy uniquely uses a fs repo but that config doesn't know the repo path. By not setting that path, running this test would create json and json.lock files when creating a KeyStore and ProfileStore. Fixes #1601
1 parent 9d89645 commit 1ec8e74

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

key/store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func NewStore(cfg *config.Config) (Store, error) {
2727

2828
switch cfg.Repo.Type {
2929
case "fs":
30+
// Don't create a localstore with the empty path, this will use the current directory
31+
if cfg.Path() == "" {
32+
return nil, fmt.Errorf("new key.LocalStore requires non-empty path")
33+
}
3034
return NewLocalStore(filepath.Join(filepath.Dir(cfg.Path()), "keystore.json"))
3135
case "mem":
3236
return NewMemStore()

lib/lib.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ func NewInstance(ctx context.Context, repoPath string, opts ...Option) (qri *Ins
356356
return
357357
}
358358

359+
// If configuration does not have a path assigned, but the repo has a path and
360+
// is stored on the filesystem, add that path to the configuration.
361+
if cfg.Repo.Type == "fs" && cfg.Path() == "" {
362+
cfg.SetPath(filepath.Join(repoPath, "config.yal"))
363+
}
364+
359365
inst := &Instance{
360366
cancel: cancel,
361367
doneCh: make(chan struct{}),

profile/store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func NewStore(cfg *config.Config) (Store, error) {
5353
return nil, err
5454
}
5555

56+
// Don't create a localstore with the empty path, this will use the current directory
57+
if cfg.Repo.Type == "fs" && cfg.Path() == "" {
58+
return nil, fmt.Errorf("new Profile.FilesystemStore requires non-empty path")
59+
}
60+
5661
keyStore, err := key.NewStore(cfg)
5762
if err != nil {
5863
return nil, err

repo/buildrepo/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func New(ctx context.Context, path string, cfg *config.Config, opts ...func(o *O
3434
opt(o)
3535
}
3636

37+
// Don't create a localstore with the empty path, this will use the current directory
38+
if cfg.Repo.Type == "fs" && cfg.Path() == "" {
39+
return nil, fmt.Errorf("buildRepo.New using filesystem requires non-empty path")
40+
}
41+
3742
var err error
3843
if o.Profiles == nil {
3944
if o.Profiles, err = profile.NewStore(cfg); err != nil {

0 commit comments

Comments
 (0)