Plugins: Optimize creation of Golang errors and slices (#69448)
* tidy up * fix tests
This commit is contained in:
@@ -44,8 +44,9 @@ func (l *Local) Find(ctx context.Context, src plugins.PluginSource) ([]*plugins.
|
||||
return []*plugins.FoundBundle{}, nil
|
||||
}
|
||||
|
||||
var pluginJSONPaths []string
|
||||
for _, path := range src.PluginURIs(ctx) {
|
||||
pluginURIs := src.PluginURIs(ctx)
|
||||
pluginJSONPaths := make([]string, 0, len(pluginURIs))
|
||||
for _, path := range pluginURIs {
|
||||
exists, err := fs.Exists(path)
|
||||
if err != nil {
|
||||
l.log.Warn("Skipping finding plugins as an error occurred", "path", path, "err", err)
|
||||
@@ -85,7 +86,7 @@ func (l *Local) Find(ctx context.Context, src plugins.PluginSource) ([]*plugins.
|
||||
foundPlugins[filepath.Dir(pluginJSONAbsPath)] = plugin
|
||||
}
|
||||
|
||||
var res = make(map[string]*plugins.FoundBundle)
|
||||
res := make(map[string]*plugins.FoundBundle)
|
||||
for pluginDir, data := range foundPlugins {
|
||||
var pluginFs plugins.FS
|
||||
pluginFs = plugins.NewLocalFS(pluginDir)
|
||||
@@ -106,7 +107,7 @@ func (l *Local) Find(ctx context.Context, src plugins.PluginSource) ([]*plugins.
|
||||
}
|
||||
}
|
||||
|
||||
var result []*plugins.FoundBundle
|
||||
result := make([]*plugins.FoundBundle, 0, len(foundPlugins))
|
||||
for dir := range foundPlugins {
|
||||
ancestors := strings.Split(dir, string(filepath.Separator))
|
||||
ancestors = ancestors[0 : len(ancestors)-1]
|
||||
|
||||
@@ -3,7 +3,6 @@ package finder
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -317,7 +316,7 @@ func TestFinder_getAbsPluginJSONPaths(t *testing.T) {
|
||||
t.Run("When scanning a folder that returns a non-handled error should return that error", func(t *testing.T) {
|
||||
origWalk := walk
|
||||
walk = func(path string, followSymlinks, detectSymlinkInfiniteLoop bool, walkFn util.WalkFunc) error {
|
||||
return walkFn(path, nil, fmt.Errorf("random error"))
|
||||
return walkFn(path, nil, errors.New("random error"))
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
walk = origWalk
|
||||
|
||||
Reference in New Issue
Block a user