-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hotfix] resource names #302
Merged
+181
−23
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
example/viam_example_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:viam_sdk/src/components/sensor/sensor.dart'; | ||
|
||
void main() { | ||
group('Subtype Tests', () { | ||
test('getResourceName', () { | ||
// Local | ||
final localName = 'my-sensor'; | ||
final localRN = Sensor.subtype.getResourceName(localName); | ||
expect(localRN.namespace, Sensor.subtype.namespace); | ||
expect(localRN.type, Sensor.subtype.resourceType); | ||
expect(localRN.subtype, Sensor.subtype.resourceSubtype); | ||
expect(localRN.remotePath, []); | ||
expect(localRN.name, localName); | ||
expect(localRN.localName, localName); | ||
|
||
// Remote | ||
final remoteName = 'my-sensor'; | ||
final remotePath = 'remote2:remote1'; | ||
final fullRemoteName = '$remotePath:$remoteName'; | ||
final remoteRN = Sensor.subtype.getResourceName(fullRemoteName); | ||
expect(remoteRN.namespace, Sensor.subtype.namespace); | ||
expect(remoteRN.type, Sensor.subtype.resourceType); | ||
expect(remoteRN.subtype, Sensor.subtype.resourceSubtype); | ||
expect(remoteRN.remotePath, remotePath.split(':')); | ||
expect(remoteRN.name, fullRemoteName); | ||
expect(remoteRN.localName, remoteName); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:viam_sdk/src/components/sensor/sensor.dart'; | ||
import 'package:viam_sdk/src/resource/manager.dart'; | ||
|
||
import '../components/sensor_test.dart'; | ||
|
||
void main() { | ||
group('ResourceManager Tests', () { | ||
group('getResource', () { | ||
test('Local', () { | ||
final localName = 'local-sensor'; | ||
final localRN = Sensor.getResourceName(localName); | ||
final localResource = FakeSensor(localName); | ||
final manager = ResourceManager(); | ||
manager.register(localRN, localResource); | ||
|
||
expect(manager.getResource<Sensor>(Sensor.getResourceName(localName)), localResource); | ||
}); | ||
|
||
test('Remote', () { | ||
final remoteName = 'remote-sensor'; | ||
final remotePath = 'remote2:remote1'; | ||
final fullRemoteName = '$remotePath:$remoteName'; | ||
final remoteRN = Sensor.subtype.getResourceName(fullRemoteName); | ||
final remoteResource = FakeSensor(fullRemoteName); | ||
final manager = ResourceManager(); | ||
manager.register(remoteRN, remoteResource); | ||
|
||
// Works with full name | ||
expect(manager.getResource<Sensor>(Sensor.getResourceName(fullRemoteName)), remoteResource); | ||
|
||
// Works with short name -- no collisions | ||
expect(manager.getResource<Sensor>(Sensor.getResourceName(remoteName)), remoteResource); | ||
}); | ||
|
||
test('Local and Remote - Same Names', () { | ||
final manager = ResourceManager(); | ||
|
||
final localName = 'my-sensor'; | ||
final localRN = Sensor.getResourceName(localName); | ||
final localResource = FakeSensor(localName); | ||
|
||
final remoteName = 'my-sensor'; | ||
final remotePath = 'remote2:remote1'; | ||
final fullRemoteName = '$remotePath:$remoteName'; | ||
final remoteRN = Sensor.subtype.getResourceName(fullRemoteName); | ||
final remoteResource = FakeSensor(fullRemoteName); | ||
|
||
manager.register(localRN, localResource); | ||
manager.register(remoteRN, remoteResource); | ||
|
||
// When using fully qualified names, it should return appropriately | ||
expect(manager.getResource<Sensor>(Sensor.getResourceName(localName)), localResource); | ||
expect(manager.getResource<Sensor>(Sensor.getResourceName(fullRemoteName)), remoteResource); | ||
|
||
// When using just `my-sensor`, it should always return the local | ||
expect(manager.getResource<Sensor>(Sensor.getResourceName(localName)), localResource); | ||
expect(manager.getResource<Sensor>(Sensor.getResourceName(remoteName)), localResource); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(q) Potentially out of scope for a hotfix but, should
resourcesWithoutRemotes
live on theResourceManager
such that we don't have to construct this new map potentially every time we callgetResource
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it anyway -- it's a good thought