Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mimoham24 committed Jun 15, 2021
1 parent f6ca798 commit c0293ff
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/app/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func initReposAndGateways(ctx context.Context, conf *Config, debug bool) (*repo.
gateways.Authenticator = auth0.New(conf.Auth0.Domain, conf.Auth0.ClientID, conf.Auth0.ClientSecret)

// github
gateways.Github = github.NewPluginRegistry()
gateways.PluginRegistry = github.NewPluginRegistry()

// release lock of all scenes
if err := repos.SceneLock.ReleaseAllLock(context.Background()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/github/plugin_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewPluginRegistry() gateway.PluginRegistry {

const source = `https://raw.githubusercontent.com/reearth/plugins/main/plugins.json`

func (d *pluginRegistry) Fetch(ctx context.Context) ([]*plugin.Metadata, error) {
func (d *pluginRegistry) FetchMetadata(ctx context.Context) ([]*plugin.Metadata, error) {

response, err := fetchURL(ctx, source)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/infrastructure/github/plugin_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ func TestNewPluginRegistry(t *testing.T) {
assert.NotNil(t, d)
}

func TestPluginRegistry_Fetch(t *testing.T) {
func TestPluginRegistry_FetchMetadata(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", "https://raw.githubusercontent.com/reearth/plugins/main/plugins.json",
httpmock.NewStringResponder(200, `[{"name": "reearth","description": "Official Plugin","createdAt": "2021-03-16T04:19:57.592Z"}]`))
d := NewPluginRegistry()
res, err := d.Fetch(context.Background())
res, err := d.FetchMetadata(context.Background())
tm, _ := time.Parse(time.RFC3339, "2021-03-16T04:19:57.592Z")

assert.Equal(t, res, []*plugin.Metadata{
Expand All @@ -37,13 +37,13 @@ func TestPluginRegistry_Fetch(t *testing.T) {
// fail: bad request
httpmock.RegisterResponder("GET", "https://raw.githubusercontent.com/reearth/plugins/main/plugins.json",
httpmock.NewStringResponder(400, `mock bad request`))
_, err = d.Fetch(context.Background())
_, err = d.FetchMetadata(context.Background())
assert.True(t, errors.As(errors.New("StatusCode=400"), &err))

// fail: unable to marshal
httpmock.RegisterResponder("GET", "https://raw.githubusercontent.com/reearth/plugins/main/plugins.json",
httpmock.NewStringResponder(200, `{"hoge": "test"}`))
_, err = d.Fetch(context.Background())
_, err = d.FetchMetadata(context.Background())
assert.True(t, errors.As(errors.New("cannot unmarshal object into Go value of type []*plugin.Metadata"), &err))

}
2 changes: 1 addition & 1 deletion internal/usecase/gateway/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ type Container struct {
Mailer Mailer
PluginRepository PluginRepository
DataSource DataSource
Github PluginRegistry
PluginRegistry PluginRegistry
File File
}
2 changes: 1 addition & 1 deletion internal/usecase/gateway/plugin_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

type PluginRegistry interface {
Fetch(ctx context.Context) ([]*plugin.Metadata, error)
FetchMetadata(ctx context.Context) ([]*plugin.Metadata, error)
}
4 changes: 2 additions & 2 deletions internal/usecase/interactor/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewPlugin(r *repo.Container, gr *gateway.Container) interfaces.Plugin {
transaction: r.Transaction,
pluginRepository: gr.PluginRepository,
file: gr.File,
pluginRegistry: gr.Github,
pluginRegistry: gr.PluginRegistry,
}
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func (i *Plugin) FetchPluginMetadata(ctx context.Context, operator *usecase.Oper
return nil, err
}

res, err := i.pluginRegistry.Fetch(ctx)
res, err := i.pluginRegistry.FetchMetadata(ctx)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c0293ff

Please sign in to comment.