@@ -8,10 +8,19 @@ import (
8
8
modulepb "go.viam.com/api/module/v1"
9
9
"go.viam.com/test"
10
10
11
+ "go.viam.com/rdk/components/base"
12
+ "go.viam.com/rdk/components/generic"
11
13
"go.viam.com/rdk/config"
14
+ "go.viam.com/rdk/examples/customresources/apis/gizmoapi"
15
+ "go.viam.com/rdk/examples/customresources/apis/summationapi"
16
+ "go.viam.com/rdk/examples/customresources/models/mybase"
17
+ "go.viam.com/rdk/examples/customresources/models/mygizmo"
18
+ "go.viam.com/rdk/examples/customresources/models/mynavigation"
19
+ "go.viam.com/rdk/examples/customresources/models/mysum"
12
20
"go.viam.com/rdk/logging"
13
21
"go.viam.com/rdk/resource"
14
22
"go.viam.com/rdk/robot"
23
+ "go.viam.com/rdk/services/navigation"
15
24
rtestutils "go.viam.com/rdk/testutils"
16
25
)
17
26
@@ -168,3 +177,66 @@ func TestDiscovery(t *testing.T) {
168
177
test .That (t , len (complexHandles .Handlers ), test .ShouldBeGreaterThan , 1 )
169
178
})
170
179
}
180
+
181
+ func TestGetModelsFromModules (t * testing.T ) {
182
+ t .Run ("no modules configured" , func (t * testing.T ) {
183
+ r := setupLocalRobotWithFakeConfig (t )
184
+ models , err := r .GetModelsFromModules (context .Background ())
185
+ test .That (t , err , test .ShouldBeNil )
186
+ test .That (t , models , test .ShouldBeEmpty )
187
+ })
188
+ t .Run ("local and registry modules are configured" , func (t * testing.T ) {
189
+ r := setupLocalRobotWithFakeConfig (t )
190
+ ctx := context .Background ()
191
+
192
+ // add modules
193
+ complexPath := rtestutils .BuildTempModule (t , "examples/customresources/demos/complexmodule" )
194
+ simplePath := rtestutils .BuildTempModule (t , "examples/customresources/demos/simplemodule" )
195
+ cfg := & config.Config {
196
+ Modules : []config.Module {
197
+ {
198
+ Name : "simple" ,
199
+ ExePath : simplePath ,
200
+ Type : config .ModuleTypeRegistry ,
201
+ },
202
+ {
203
+ Name : "complex" ,
204
+ ExePath : complexPath ,
205
+ Type : config .ModuleTypeLocal ,
206
+ },
207
+ },
208
+ }
209
+ r .Reconfigure (ctx , cfg )
210
+ models , err := r .GetModelsFromModules (context .Background ())
211
+ test .That (t , err , test .ShouldBeNil )
212
+ test .That (t , models , test .ShouldHaveLength , 5 )
213
+
214
+ for _ , model := range models {
215
+ switch model .Model {
216
+ case mygizmo .Model :
217
+ test .That (t , model .FromLocalModule , test .ShouldEqual , true )
218
+ test .That (t , model .ModuleName , test .ShouldEqual , "complex" )
219
+ test .That (t , model .API , test .ShouldResemble , gizmoapi .API )
220
+ case mysum .Model :
221
+ test .That (t , model .FromLocalModule , test .ShouldEqual , true )
222
+ test .That (t , model .ModuleName , test .ShouldEqual , "complex" )
223
+ test .That (t , model .API , test .ShouldResemble , summationapi .API )
224
+ case mybase .Model :
225
+ test .That (t , model .FromLocalModule , test .ShouldEqual , true )
226
+ test .That (t , model .ModuleName , test .ShouldEqual , "complex" )
227
+ test .That (t , model .API , test .ShouldResemble , base .API )
228
+ case mynavigation .Model :
229
+ test .That (t , model .FromLocalModule , test .ShouldEqual , true )
230
+ test .That (t , model .ModuleName , test .ShouldEqual , "complex" )
231
+ test .That (t , model .API , test .ShouldResemble , navigation .API )
232
+ case resource .NewModel ("acme" , "demo" , "mycounter" ):
233
+ test .That (t , model .FromLocalModule , test .ShouldEqual , false )
234
+ test .That (t , model .ModuleName , test .ShouldEqual , "simple" )
235
+ test .That (t , model .API , test .ShouldResemble , generic .API )
236
+ default :
237
+ t .Fail ()
238
+ t .Logf ("test GetModelsFromModules failure: unrecoginzed model %v" , model .Model )
239
+ }
240
+ }
241
+ })
242
+ }
0 commit comments