@@ -3,6 +3,7 @@ package board_test
3
3
import (
4
4
"context"
5
5
"net"
6
+ "slices"
6
7
"testing"
7
8
"time"
8
9
@@ -219,3 +220,69 @@ func TestWorkingClient(t *testing.T) {
219
220
test .That (t , conn .Close (), test .ShouldBeNil )
220
221
})
221
222
}
223
+
224
+ // these tests validate that for modular boards(which rely on client.go's board interface)
225
+ // we will only add new pins to the cached name lists.
226
+ func TestClientNames (t * testing.T ) {
227
+ logger := logging .NewTestLogger (t )
228
+ injectBoard := & inject.Board {}
229
+
230
+ listener , cleanup := setupService (t , injectBoard )
231
+ defer cleanup ()
232
+ t .Run ("test analog names are cached correctly in the client" , func (t * testing.T ) {
233
+ ctx := context .Background ()
234
+ conn , err := viamgrpc .Dial (ctx , listener .Addr ().String (), logger )
235
+ test .That (t , err , test .ShouldBeNil )
236
+ client , err := board .NewClientFromConn (ctx , conn , "" , board .Named (testBoardName ), logger )
237
+ test .That (t , err , test .ShouldBeNil )
238
+
239
+ nameFunc := func (name string ) error {
240
+ _ , err = client .AnalogByName (name )
241
+ return err
242
+ }
243
+ testNamesAPI (t , client .AnalogNames , nameFunc , "Analog" )
244
+
245
+ test .That (t , conn .Close (), test .ShouldBeNil )
246
+ })
247
+
248
+ t .Run ("test interrupt names are cached correctly in the client" , func (t * testing.T ) {
249
+ ctx := context .Background ()
250
+ conn , err := viamgrpc .Dial (ctx , listener .Addr ().String (), logger )
251
+ test .That (t , err , test .ShouldBeNil )
252
+ client , err := board .NewClientFromConn (ctx , conn , "" , board .Named (testBoardName ), logger )
253
+ test .That (t , err , test .ShouldBeNil )
254
+
255
+ nameFunc := func (name string ) error {
256
+ _ , err = client .DigitalInterruptByName (name )
257
+ return err
258
+ }
259
+ testNamesAPI (t , client .DigitalInterruptNames , nameFunc , "DigitalInterrupt" )
260
+ test .That (t , conn .Close (), test .ShouldBeNil )
261
+ })
262
+ }
263
+
264
+ func testNamesAPI (t * testing.T , namesFunc func () []string , nameFunc func (string ) error , name string ) {
265
+ t .Helper ()
266
+ names := namesFunc ()
267
+ test .That (t , len (names ), test .ShouldEqual , 0 )
268
+ name1 := name + "1"
269
+ err := nameFunc (name1 )
270
+ test .That (t , err , test .ShouldBeNil )
271
+ names = namesFunc ()
272
+ test .That (t , len (names ), test .ShouldEqual , 1 )
273
+ test .That (t , slices .Contains (names , name1 ), test .ShouldBeTrue )
274
+
275
+ name2 := name + "2"
276
+ err = nameFunc (name2 )
277
+ test .That (t , err , test .ShouldBeNil )
278
+
279
+ names = namesFunc ()
280
+ test .That (t , len (names ), test .ShouldEqual , 2 )
281
+ test .That (t , slices .Contains (names , name2 ), test .ShouldBeTrue )
282
+
283
+ err = nameFunc (name1 )
284
+ test .That (t , err , test .ShouldBeNil )
285
+ names = namesFunc ()
286
+ test .That (t , len (names ), test .ShouldEqual , 2 )
287
+ test .That (t , slices .Contains (names , name1 ), test .ShouldBeTrue )
288
+ }
0 commit comments