diff --git a/internal/app/repo.go b/internal/app/repo.go index 9857e902..ea1b4897 100644 --- a/internal/app/repo.go +++ b/internal/app/repo.go @@ -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 { diff --git a/internal/infrastructure/github/plugin_registry.go b/internal/infrastructure/github/plugin_registry.go index 90c8562e..84a3cbe0 100644 --- a/internal/infrastructure/github/plugin_registry.go +++ b/internal/infrastructure/github/plugin_registry.go @@ -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 { diff --git a/internal/infrastructure/github/plugin_registry_test.go b/internal/infrastructure/github/plugin_registry_test.go index 9d90373f..075795fe 100644 --- a/internal/infrastructure/github/plugin_registry_test.go +++ b/internal/infrastructure/github/plugin_registry_test.go @@ -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{ @@ -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)) } diff --git a/internal/usecase/gateway/container.go b/internal/usecase/gateway/container.go index a7b5a37e..5f730d7e 100644 --- a/internal/usecase/gateway/container.go +++ b/internal/usecase/gateway/container.go @@ -5,6 +5,6 @@ type Container struct { Mailer Mailer PluginRepository PluginRepository DataSource DataSource - Github PluginRegistry + PluginRegistry PluginRegistry File File } diff --git a/internal/usecase/gateway/plugin_registry.go b/internal/usecase/gateway/plugin_registry.go index 62be7ada..7c1ef7cf 100644 --- a/internal/usecase/gateway/plugin_registry.go +++ b/internal/usecase/gateway/plugin_registry.go @@ -7,5 +7,5 @@ import ( ) type PluginRegistry interface { - Fetch(ctx context.Context) ([]*plugin.Metadata, error) + FetchMetadata(ctx context.Context) ([]*plugin.Metadata, error) } diff --git a/internal/usecase/interactor/plugin.go b/internal/usecase/interactor/plugin.go index 87ea36eb..c440ef4d 100644 --- a/internal/usecase/interactor/plugin.go +++ b/internal/usecase/interactor/plugin.go @@ -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, } } @@ -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 }