Skip to content

Commit

Permalink
register and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston committed Jan 2, 2025
1 parent 51762f2 commit d20195c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/src/resource/registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Registry {
registerSubtype(ResourceRegistration(Sensor.subtype, (name, channel) => SensorClient(name, channel)));
registerSubtype(ResourceRegistration(Servo.subtype, (name, channel) => ServoClient(name, channel)));
registerSubtype(ResourceRegistration(VisionClient.subtype, (name, channel) => VisionClient(name, channel)));
registerSubtype(ResourceRegistration(DiscoveryClient.subtype, (name, channel) => DiscoverClient(name, channel)));
}

/// The [Subtype] available in the SDK
Expand Down
39 changes: 39 additions & 0 deletions test/unit_test/services/discovery_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:fixnum/fixnum.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:viam_sdk/protos/service/discovery.dart';
import 'package:viam_sdk/src/gen/common/v1/common.pb.dart';
import 'package:viam_sdk/src/gen/service/discovery/v1/discovery.pbgrpc.dart';
import 'package:viam_sdk/viam_sdk.dart';

import '../mocks/mock_response_future.dart';
import '../mocks/service_clients_mocks.mocks.dart';

class FakeDiscoveryClient extends DiscoverClient {
@override
DiscoveryServiceClient get client => _client;

final MockDiscoveryServiceClient _client;

FakeDiscoveryClient(super.name, super.channel, this._client);
}

void main() {
late DiscoveryClient client;
late MockDiscoveryServiceClient serviceClient;

setUp(() {
serviceClient = MockDiscoveryServiceClient();
client = FakeDiscoveryClient('discovery', MockClientChannelBase(), serviceClient);
});

group('Discovery RPC Client Tests', () {
test('discoverResources', () async {
final expected = [ComponentConfig()];
when(serviceClient.discoverResources(any))
.thenAnswer((_) => MockResponseFuture.value(DiscoverResourcesResponse(discovery: expected)));
final response = await client.discoverResources('discoveryName');
expect(response, equals(expected));
});
});
}

0 comments on commit d20195c

Please sign in to comment.