Browse Source

pkg/plugins: remove LocalRegistry.SpecsPaths()

This field was exported, but never mutated outside of the package, and
effectively a rather "creative" way to define a method on LocalRegistry.

While un-exporting also store these paths in a field, instead of constructing
them on every call, as the results won't change during the lifecycle of the
LocalRegistry.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 years ago
parent
commit
4af4adc7ba
2 changed files with 7 additions and 11 deletions
  1. 4 4
      pkg/plugins/discovery.go
  2. 3 7
      pkg/plugins/discovery_test.go

+ 4 - 4
pkg/plugins/discovery.go

@@ -21,12 +21,12 @@ var (
 
 // LocalRegistry defines a registry that is local (using unix socket).
 type LocalRegistry struct {
-	SpecsPaths func() []string
+	specsPaths []string
 }
 
 func NewLocalRegistry() LocalRegistry {
 	return LocalRegistry{
-		SpecsPaths: specsPaths,
+		specsPaths: specsPaths(),
 	}
 }
 
@@ -53,7 +53,7 @@ func (l *LocalRegistry) Scan() ([]string, error) {
 		}
 	}
 
-	for _, p := range l.SpecsPaths() {
+	for _, p := range l.specsPaths {
 		dirEntries, err = os.ReadDir(p)
 		if err != nil && !os.IsNotExist(err) {
 			return nil, errors.Wrap(err, "error reading dir entries")
@@ -95,7 +95,7 @@ func (l *LocalRegistry) Plugin(name string) (*Plugin, error) {
 	}
 
 	var txtSpecPaths []string
-	for _, p := range l.SpecsPaths() {
+	for _, p := range l.specsPaths {
 		txtSpecPaths = append(txtSpecPaths, pluginPaths(p, name, ".spec")...)
 		txtSpecPaths = append(txtSpecPaths, pluginPaths(p, name, ".json")...)
 	}

+ 3 - 7
pkg/plugins/discovery_test.go

@@ -15,13 +15,9 @@ func Setup(t *testing.T) (string, func(), LocalRegistry) {
 	socketsPath = tmpdir
 
 	return tmpdir, func() {
-			socketsPath = backup
-			os.RemoveAll(tmpdir)
-		}, LocalRegistry{
-			func() []string {
-				return []string{tmpdir}
-			},
-		}
+		socketsPath = backup
+		os.RemoveAll(tmpdir)
+	}, LocalRegistry{specsPaths: []string{tmpdir}}
 }
 
 func TestFileSpecPlugin(t *testing.T) {