Plugins: Refactor loader + finder to support multiple sourcing methods (#64735)

* it's cdn time

* tidy body closing

* auto signed

* fix close

* update log name

* remove comments
This commit is contained in:
Will Browne
2023-03-20 14:35:49 +01:00
committed by GitHub
parent eba2c7b522
commit ee2dd62a1f
25 changed files with 389 additions and 223 deletions
+2 -2
View File
@@ -16,11 +16,11 @@ type Service struct {
pluginRegistry registry.Service
}
func ProvideService(pluginRegistry registry.Service, pluginSources sources.Resolver,
func ProvideService(pluginRegistry registry.Service, pluginSources sources.Registry,
pluginLoader loader.Service) (*Service, error) {
ctx := context.Background()
for _, ps := range pluginSources.List(ctx) {
if _, err := pluginLoader.Load(ctx, ps.Class, ps.Paths); err != nil {
if _, err := pluginLoader.Load(ctx, ps); err != nil {
return nil, err
}
}
+17 -9
View File
@@ -15,21 +15,29 @@ func TestStore_ProvideService(t *testing.T) {
t.Run("Plugin sources are added in order", func(t *testing.T) {
var addedPaths []string
l := &fakes.FakeLoader{
LoadFunc: func(ctx context.Context, class plugins.Class, paths []string) ([]*plugins.Plugin, error) {
addedPaths = append(addedPaths, paths...)
LoadFunc: func(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
addedPaths = append(addedPaths, src.PluginURIs(ctx)...)
return nil, nil
},
}
srcs := &fakes.FakeSources{ListFunc: func(_ context.Context) []plugins.PluginSource {
srcs := &fakes.FakeSourceRegistry{ListFunc: func(_ context.Context) []plugins.PluginSource {
return []plugins.PluginSource{
{
Class: plugins.Bundled,
Paths: []string{"path1"},
&fakes.FakePluginSource{
PluginClassFunc: func(ctx context.Context) plugins.Class {
return plugins.Bundled
},
PluginURIsFunc: func(ctx context.Context) []string {
return []string{"path1"}
},
},
{
Class: plugins.External,
Paths: []string{"path2", "path3"},
&fakes.FakePluginSource{
PluginClassFunc: func(ctx context.Context) plugins.Class {
return plugins.External
},
PluginURIsFunc: func(ctx context.Context) []string {
return []string{"path2", "path3"}
},
},
}
}}