@@ -19,11 +19,12 @@ import (
1919
2020func TestFilePluginRepoListSLOPlugins (t * testing.T ) {
2121 tests := map [string ]struct {
22- fss func () []fs.FS
23- mock func (mslopl * fsmock.SLOPluginLoader , mslipl * fsmock.SLIPluginLoader )
24- expPlugins map [string ]pluginengineslo.Plugin
25- expLoadErr bool
26- expErr bool
22+ failOnError bool
23+ fss func () []fs.FS
24+ mock func (mslopl * fsmock.SLOPluginLoader , mslipl * fsmock.SLIPluginLoader )
25+ expPlugins map [string ]pluginengineslo.Plugin
26+ expLoadErr bool
27+ expErr bool
2728 }{
2829 "Having no files, should return empty list of plugins." : {
2930 fss : func () []fs.FS { return nil },
@@ -113,6 +114,26 @@ func TestFilePluginRepoListSLOPlugins(t *testing.T) {
113114 "p1" : {ID : "p1" },
114115 },
115116 },
117+
118+ "Having an error while loading a plugin on strict mode, should fail." : {
119+ failOnError : true ,
120+ fss : func () []fs.FS {
121+ m1 := make (fstest.MapFS )
122+ m1 ["m1/pl1/plugin.go" ] = & fstest.MapFile {Data : []byte ("p1" )}
123+ m1 ["m1/pl2/plugin.go" ] = & fstest.MapFile {Data : []byte ("p2" )}
124+
125+ return []fs.FS {m1 }
126+ },
127+ mock : func (mslopl * fsmock.SLOPluginLoader , mslipl * fsmock.SLIPluginLoader ) {
128+ mslipl .On ("LoadRawSLIPlugin" , mock .Anything , "p1" ).Once ().Return (nil , fmt .Errorf ("something" ))
129+ mslipl .On ("LoadRawSLIPlugin" , mock .Anything , "p2" ).Once ().Return (nil , fmt .Errorf ("something" ))
130+
131+ mslopl .On ("LoadRawPlugin" , mock .Anything , "p1" ).Once ().Return (& pluginengineslo.Plugin {ID : "p1" }, nil )
132+ mslopl .On ("LoadRawPlugin" , mock .Anything , "p2" ).Once ().Return (nil , fmt .Errorf ("something" ))
133+
134+ },
135+ expLoadErr : true ,
136+ },
116137 }
117138
118139 for name , test := range tests {
@@ -124,7 +145,7 @@ func TestFilePluginRepoListSLOPlugins(t *testing.T) {
124145 test .mock (mslopl , mslipl )
125146
126147 // Create repository and load plugins.
127- repo , err := storagefs .NewFilePluginRepo (log .Noop , mslipl , mslopl , test .fss ()... )
148+ repo , err := storagefs .NewFilePluginRepo (log .Noop , test . failOnError , mslipl , mslopl , test .fss ()... )
128149 if test .expLoadErr {
129150 assert .Error (err )
130151 return
@@ -185,7 +206,7 @@ func TestFilePluginRepoGetSLOPlugin(t *testing.T) {
185206 test .mock (mslopl , mslipl )
186207
187208 // Create repository and load plugins.
188- repo , err := storagefs .NewFilePluginRepo (log .Noop , mslipl , mslopl , test .fss ()... )
209+ repo , err := storagefs .NewFilePluginRepo (log .Noop , false , mslipl , mslopl , test .fss ()... )
189210 require .NoError (err )
190211
191212 plugin , err := repo .GetSLOPlugin (t .Context (), test .pluginID )
@@ -200,11 +221,12 @@ func TestFilePluginRepoGetSLOPlugin(t *testing.T) {
200221
201222func TestFilePluginRepoListSLIPlugins (t * testing.T ) {
202223 tests := map [string ]struct {
203- fss func () []fs.FS
204- mock func (mslopl * fsmock.SLOPluginLoader , mslipl * fsmock.SLIPluginLoader )
205- expPlugins map [string ]pluginenginesli.SLIPlugin
206- expLoadErr bool
207- expErr bool
224+ failOnError bool
225+ fss func () []fs.FS
226+ mock func (mslopl * fsmock.SLOPluginLoader , mslipl * fsmock.SLIPluginLoader )
227+ expPlugins map [string ]pluginenginesli.SLIPlugin
228+ expLoadErr bool
229+ expErr bool
208230 }{
209231 "Having no files, should return empty list of plugins." : {
210232 fss : func () []fs.FS { return nil },
@@ -281,6 +303,24 @@ func TestFilePluginRepoListSLIPlugins(t *testing.T) {
281303 "p1" : {ID : "p1" },
282304 },
283305 },
306+
307+ "Having an error while loading a plugin on strict mode, should fail." : {
308+ failOnError : true ,
309+ fss : func () []fs.FS {
310+ m1 := make (fstest.MapFS )
311+ m1 ["m1/pl1/plugin.go" ] = & fstest.MapFile {Data : []byte ("p1" )}
312+ m1 ["m1/pl2/plugin.go" ] = & fstest.MapFile {Data : []byte ("p2" )}
313+
314+ return []fs.FS {m1 }
315+ },
316+ mock : func (mslopl * fsmock.SLOPluginLoader , mslipl * fsmock.SLIPluginLoader ) {
317+ mslipl .On ("LoadRawSLIPlugin" , mock .Anything , "p1" ).Once ().Return (& pluginenginesli.SLIPlugin {ID : "p1" }, nil )
318+ mslipl .On ("LoadRawSLIPlugin" , mock .Anything , "p2" ).Once ().Return (nil , fmt .Errorf ("something" ))
319+ mslopl .On ("LoadRawPlugin" , mock .Anything , "p2" ).Once ().Return (nil , fmt .Errorf ("something" ))
320+
321+ },
322+ expLoadErr : true ,
323+ },
284324 }
285325
286326 for name , test := range tests {
@@ -292,7 +332,7 @@ func TestFilePluginRepoListSLIPlugins(t *testing.T) {
292332 test .mock (mslopl , mslipl )
293333
294334 // Create repository and load plugins.
295- repo , err := storagefs .NewFilePluginRepo (log .Noop , mslipl , mslopl , test .fss ()... )
335+ repo , err := storagefs .NewFilePluginRepo (log .Noop , test . failOnError , mslipl , mslopl , test .fss ()... )
296336 if test .expLoadErr {
297337 assert .Error (err )
298338 return
@@ -350,7 +390,7 @@ func TestFilePluginRepoGetSLIPlugin(t *testing.T) {
350390 test .mock (mslopl , mslipl )
351391
352392 // Create repository and load plugins.
353- repo , err := storagefs .NewFilePluginRepo (log .Noop , mslipl , mslopl , test .fss ()... )
393+ repo , err := storagefs .NewFilePluginRepo (log .Noop , false , mslipl , mslopl , test .fss ()... )
354394 require .NoError (err )
355395
356396 plugin , err := repo .GetSLIPlugin (t .Context (), test .pluginID )
0 commit comments