Skip to content

Commit

Permalink
fix(repo): Don't use blank path for new repo in tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dustmop committed Jan 22, 2021
1 parent 9d89645 commit 1ec8e74
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions key/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func NewStore(cfg *config.Config) (Store, error) {

switch cfg.Repo.Type {
case "fs":
// Don't create a localstore with the empty path, this will use the current directory
if cfg.Path() == "" {
return nil, fmt.Errorf("new key.LocalStore requires non-empty path")
}
return NewLocalStore(filepath.Join(filepath.Dir(cfg.Path()), "keystore.json"))
case "mem":
return NewMemStore()
Expand Down
6 changes: 6 additions & 0 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ func NewInstance(ctx context.Context, repoPath string, opts ...Option) (qri *Ins
return
}

// If configuration does not have a path assigned, but the repo has a path and
// is stored on the filesystem, add that path to the configuration.
if cfg.Repo.Type == "fs" && cfg.Path() == "" {
cfg.SetPath(filepath.Join(repoPath, "config.yal"))
}

inst := &Instance{
cancel: cancel,
doneCh: make(chan struct{}),
Expand Down
5 changes: 5 additions & 0 deletions profile/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func NewStore(cfg *config.Config) (Store, error) {
return nil, err
}

// Don't create a localstore with the empty path, this will use the current directory
if cfg.Repo.Type == "fs" && cfg.Path() == "" {
return nil, fmt.Errorf("new Profile.FilesystemStore requires non-empty path")
}

keyStore, err := key.NewStore(cfg)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions repo/buildrepo/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func New(ctx context.Context, path string, cfg *config.Config, opts ...func(o *O
opt(o)
}

// Don't create a localstore with the empty path, this will use the current directory
if cfg.Repo.Type == "fs" && cfg.Path() == "" {
return nil, fmt.Errorf("buildRepo.New using filesystem requires non-empty path")
}

var err error
if o.Profiles == nil {
if o.Profiles, err = profile.NewStore(cfg); err != nil {
Expand Down

0 comments on commit 1ec8e74

Please sign in to comment.