Skip to content

Commit

Permalink
feat(mock registry): add support for mock registry config
Browse files Browse the repository at this point in the history
set registry.location to "mock" and qri will create a mock registry, we'll use this in tests elsewhere.

Long term it'd be nice to not have to bundle testing code with our production binary, but the overhead of maintaining a testing-oriented binary is a little too much at the moment.
  • Loading branch information
b5 committed Sep 10, 2019
1 parent f1f14d4 commit 7b7b98b
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/qri-io/qri/config/migrate"
"github.com/qri-io/qri/p2p"
"github.com/qri-io/qri/registry/regclient"
regmock "github.com/qri-io/qri/registry/regserver/mock"
"github.com/qri-io/qri/remote"
"github.com/qri-io/qri/repo"
fsrepo "github.com/qri-io/qri/repo/fs"
Expand Down Expand Up @@ -316,7 +317,7 @@ func NewInstance(ctx context.Context, repoPath string, opts ...Option) (qri *Ins
}

if inst.registry == nil {
inst.registry = newRegClient(cfg)
inst.registry = newRegClient(ctx, cfg)
}

if o.repo != nil {
Expand Down Expand Up @@ -429,13 +430,27 @@ func newStore(ctx context.Context, cfg *config.Config) (store cafs.Filestore, er
}
}

func newRegClient(cfg *config.Config) (rc *regclient.Client) {
if cfg.Registry != nil && cfg.Registry.Location != "" {
rc = regclient.NewClient(&regclient.Config{
Location: cfg.Registry.Location,
})
func newRegClient(ctx context.Context, cfg *config.Config) (rc *regclient.Client) {
if cfg.Registry != nil {
switch cfg.Registry.Location {
case "mock":
cli, server := regmock.NewMockServerRegistry(regmock.NewMemRegistry())
log.Infof("mock registry serving at: '%s'", server.URL)
go func() {
<-ctx.Done()
server.Close()
}()
return cli
case "":
return rc
default:
return regclient.NewClient(&regclient.Config{
Location: cfg.Registry.Location,
})
}
}
return

return nil
}

func newRepo(path string, cfg *config.Config, store cafs.Filestore) (r repo.Repo, err error) {
Expand Down

0 comments on commit 7b7b98b

Please sign in to comment.