-
Notifications
You must be signed in to change notification settings - Fork 15
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
test: Mock tests for SshnpCore #565
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1cc8d11
refactor: organize tests to match new refactor tree structure
XavierChanth 96332c5
docs: remove old class diagrams
XavierChanth 0cf3e40
chore: make logger injectable for testing
XavierChanth a6de5e8
chore: simplify logger setup
XavierChanth 9bcc1c9
chore: clean up logger
XavierChanth 9e0336d
test: sshnp core constructor
XavierChanth 924736f
chore: remove unused import
XavierChanth ad72708
fix: tests
XavierChanth bface01
Merge branch 'noports_core_unit_tests' into unit_tests_2
XavierChanth b046707
chore: remove unused line
XavierChanth a54fb29
chore: mark async init members as visible for testing
XavierChanth 761f230
chore: sshrvd channel is required on sshnp core
XavierChanth ae0ec93
test: sshnp_core mocks
XavierChanth 50c11b6
Merge remote-tracking branch 'origin/trunk' into unit_tests_2
XavierChanth 9c5cd41
Merge remote-tracking branch 'origin/trunk' into unit_tests_2
XavierChanth 1cbf54b
chore: remove unnecessary non-null assertions
XavierChanth 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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
packages/noports_core/test/sshnp/sshnp_core_constants.dart
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,14 @@ | ||
class TestingKeyPair { | ||
static const public = 'ssh-ed25519 ' | ||
'AAAAC3NzaC1lZDI1NTE5AAAAIGoKAULs01V4Lqwdyz+IZLXkSfI+6HBJmFoAzCpRvoda ' | ||
'for-testing-do-not-use'; | ||
|
||
static const private = '''-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACBqCgFC7NNVeC6sHcs/iGS15EnyPuhwSZhaAMwqUb6HWgAAAKBJvoc+Sb6H | ||
PgAAAAtzc2gtZWQyNTUxOQAAACBqCgFC7NNVeC6sHcs/iGS15EnyPuhwSZhaAMwqUb6HWg | ||
AAAEBnVg+o0CCLV0NqeXy6A1+w236zA8D6lqFe2mmyZbRqpWoKAULs01V4Lqwdyz+IZLXk | ||
SfI+6HBJmFoAzCpRvodaAAAAFmZvci10ZXN0aW5nLWRvLW5vdC11c2UBAgMEBQYH | ||
-----END OPENSSH PRIVATE KEY----- | ||
'''; | ||
} |
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,108 @@ | ||
import 'package:at_client/at_client.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:noports_core/sshnp_foundation.dart'; | ||
|
||
import 'sshnp_core_constants.dart'; | ||
|
||
/// Function Stubbing | ||
abstract class FunctionCaller { | ||
void call(); | ||
} | ||
|
||
class FunctionStub extends Mock implements FunctionCaller {} | ||
|
||
/// Mocked Classes | ||
class MockAtClient extends Mock implements AtClient {} | ||
|
||
class MockSshnpParams extends Mock implements SshnpParams {} | ||
|
||
class MockSshnpdChannel extends Mock implements SshnpdChannel {} | ||
|
||
class MockSshrvdChannel extends Mock implements SshrvdChannel {} | ||
|
||
/// Stubbed [SshnpCore] (minimum viable implementation of [SshnpCore]) | ||
class StubbedSshnpCore extends SshnpCore with StubbedAsyncInitializationMixin { | ||
FunctionStub? _stubbedFindLocalPortIfRequired; | ||
|
||
void stubFindLocalPortIfRequired( | ||
FunctionStub stubbedFindLocalPortIfRequired, | ||
) { | ||
_stubbedFindLocalPortIfRequired = stubbedFindLocalPortIfRequired; | ||
} | ||
|
||
StubbedSshnpCore({ | ||
required super.atClient, | ||
required super.params, | ||
SshnpdChannel? sshnpdChannel, | ||
SshrvdChannel? sshrvdChannel, | ||
}) : _sshnpdChannel = sshnpdChannel, | ||
_sshrvdChannel = sshrvdChannel; | ||
|
||
@override | ||
Future<void> initialize() async { | ||
await super.initialize(); | ||
completeInitialization(); | ||
} | ||
|
||
@override | ||
AtSshKeyPair? get identityKeyPair => _identityKeyPair; | ||
final _identityKeyPair = | ||
AtSshKeyPair.fromPem(TestingKeyPair.private, identifier: 'testing'); | ||
|
||
@override | ||
AtSshKeyUtil get keyUtil => throw UnimplementedError(); | ||
|
||
@override | ||
Future<SshnpResult> run() => throw UnimplementedError(); | ||
|
||
@override | ||
SshnpdChannel get sshnpdChannel => | ||
_sshnpdChannel ?? (throw UnimplementedError()); | ||
final SshnpdChannel? _sshnpdChannel; | ||
|
||
@override | ||
SshrvdChannel get sshrvdChannel => | ||
_sshrvdChannel ?? (throw UnimplementedError()); | ||
final SshrvdChannel? _sshrvdChannel; | ||
|
||
@override | ||
Future<void> findLocalPortIfRequired() { | ||
_stubbedFindLocalPortIfRequired?.call(); | ||
return super.findLocalPortIfRequired(); | ||
} | ||
} | ||
|
||
/// Stubbed mixin wrapper | ||
mixin StubbedAsyncInitializationMixin on AsyncInitialization { | ||
late FunctionStub _mockCallInitialization; | ||
late FunctionStub _mockInitialize; | ||
late FunctionStub _mockCompleteInitialization; | ||
|
||
void stubAsyncInitialization({ | ||
required FunctionStub mockCallInitialization, | ||
required FunctionStub mockInitialize, | ||
required FunctionStub mockCompleteInitialization, | ||
}) { | ||
_mockCallInitialization = mockCallInitialization; | ||
_mockInitialize = mockInitialize; | ||
_mockCompleteInitialization = mockCompleteInitialization; | ||
} | ||
|
||
@override | ||
Future<void> callInitialization() async { | ||
_mockCallInitialization.call(); | ||
return super.callInitialization(); | ||
} | ||
|
||
@override | ||
Future<void> initialize() async { | ||
_mockInitialize.call(); | ||
await super.initialize(); | ||
} | ||
|
||
@override | ||
void completeInitialization() { | ||
_mockCompleteInitialization.call(); | ||
super.completeInitialization(); | ||
} | ||
} |
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.
Why not just generate at test time?
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.
I can open another PR which generates the temp keys later on, it was quicker for me to hard code.