@@ -96,7 +96,7 @@ func setupModManager(
96
96
func TestModManagerFunctions (t * testing.T ) {
97
97
// Precompile module copies to avoid timeout issues when building takes too long.
98
98
modPath := rtestutils .BuildTempModule (t , "examples/customresources/demos/simplemodule" )
99
- modPath2 := rtestutils .BuildTempModule (t , "examples/customresources/demos/simplemodule " )
99
+ modPath2 := rtestutils .BuildTempModule (t , "examples/customresources/demos/complexmodule " )
100
100
101
101
for _ , mode := range []string {"tcp" , "unix" } {
102
102
t .Run (mode , func (t * testing.T ) {
@@ -207,20 +207,35 @@ func TestModManagerFunctions(t *testing.T) {
207
207
t .Log ("test AllModels" )
208
208
modCfg2 := config.Module {
209
209
Name : "simple-module2" ,
210
- ExePath : modPath ,
210
+ ExePath : modPath2 ,
211
211
Type : config .ModuleTypeLocal ,
212
212
}
213
213
err = mgr .Add (ctx , modCfg2 )
214
214
test .That (t , err , test .ShouldBeNil )
215
215
models := mgr .AllModels ()
216
+
217
+ type expectedModel struct {
218
+ model resource.Model
219
+ api resource.API
220
+ }
221
+
222
+ expectedMod2Models := []expectedModel {
223
+ {resource .NewModel ("acme" , "demo" , "mycounter" ), resource .NewAPI ("rdk" , "component" , "generic" )},
224
+ {resource .NewModel ("acme" , "demo" , "mygizmo" ), resource .NewAPI ("acme" , "component" , "gizmo" )},
225
+ {resource .NewModel ("acme" , "demo" , "mysum" ), resource .NewAPI ("acme" , "service" , "summation" )},
226
+ {resource .NewModel ("acme" , "demo" , "mynavigation" ), resource .NewAPI ("rdk" , "service" , "navigation" )},
227
+ {resource .NewModel ("acme" , "demo" , "mybase" ), resource .NewAPI ("rdk" , "component" , "base" )},
228
+ }
229
+
216
230
for _ , model := range models {
217
- test .That (t , model .Model , test .ShouldResemble , resource .NewModel ("acme" , "demo" , "mycounter" ))
218
- test .That (t , model .API , test .ShouldResemble , resource .NewAPI ("rdk" , "component" , "generic" ))
219
231
switch model .ModuleName {
220
232
case "simple-module" :
221
233
test .That (t , model .FromLocalModule , test .ShouldEqual , false )
234
+ test .That (t , model .Model , test .ShouldResemble , resource .NewModel ("acme" , "demo" , "mycounter" ))
235
+ test .That (t , model .API , test .ShouldResemble , resource .NewAPI ("rdk" , "component" , "generic" ))
222
236
case "simple-module2" :
223
237
test .That (t , model .FromLocalModule , test .ShouldEqual , true )
238
+ test .That (t , expectedModel {model .Model , model .API }, test .ShouldBeIn , expectedMod2Models )
224
239
default :
225
240
t .Fail ()
226
241
t .Logf ("test AllModels failure: unrecoginzed moduleName %v" , model .ModuleName )
@@ -301,6 +316,19 @@ func TestModManagerFunctions(t *testing.T) {
301
316
test .That (t , err , test .ShouldBeNil )
302
317
test .That (t , ret ["total" ], test .ShouldEqual , 24 )
303
318
319
+ // Reconfigure module with duplicate ExePath.
320
+ err = mgr .Add (ctx , modCfg2 )
321
+ test .That (t , err , test .ShouldBeNil )
322
+
323
+ modCfg .ExePath = modPath2
324
+ _ , err = mgr .Reconfigure (ctx , modCfg )
325
+ test .That (t , err , test .ShouldNotBeNil )
326
+ test .That (t , err .Error (), test .ShouldContainSubstring ,
327
+ "An existing module simple-module2 already exists with the same executable path as module simple-module" )
328
+
329
+ _ , err = mgr .Remove (modCfg2 .Name )
330
+ test .That (t , err , test .ShouldBeNil )
331
+
304
332
// Change underlying binary path of module to be a different copy of the same module
305
333
modCfg .ExePath = modPath2
306
334
@@ -495,6 +523,15 @@ func TestModManagerValidation(t *testing.T) {
495
523
test .That (t , err , test .ShouldNotBeNil )
496
524
test .That (t , err .Error (), test .ShouldResemble ,
497
525
"rpc error: code = DeadlineExceeded desc = context deadline exceeded" )
526
+
527
+ modCfg = config.Module {
528
+ Name : "second-module" ,
529
+ ExePath : modPath ,
530
+ }
531
+ err = mgr .Add (ctx , modCfg )
532
+ test .That (t , err , test .ShouldNotBeNil )
533
+ test .That (t , err .Error (), test .ShouldResemble ,
534
+ "An existing module complex-module already exists with the same executable path as module second-module" )
498
535
}
499
536
500
537
func TestModuleReloading (t * testing.T ) {
0 commit comments