Skip to content

Commit

Permalink
test: checkin sshnp_result_test
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierChanth committed Oct 20, 2023
1 parent 63d1cb2 commit 3873d70
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
1 change: 0 additions & 1 deletion .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ jobs:
- name: dart test
working-directory: packages/noports_core
run: dart test

23 changes: 12 additions & 11 deletions packages/noports_core/lib/src/sshnp/sshnp_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ mixin SSHNPConnectionBean<Bean> on SSHNPResult {
}
}

const _optionsWithPrivateKey = [
@visibleForTesting
const optionsWithPrivateKey = [
'-o StrictHostKeyChecking=accept-new',
'-o IdentitiesOnly=yes'
];
Expand Down Expand Up @@ -82,17 +83,17 @@ class SSHNPCommand<Bean> extends SSHNPSuccess with SSHNPConnectionBean<Bean> {

final List<String> sshOptions;

SSHNPCommand(
{required this.localPort,
required this.remoteUsername,
required this.host,
this.command = 'ssh',
List<String>? localSshOptions,
this.privateKeyFileName,
Bean? connectionBean})
: sshOptions = [
SSHNPCommand({
required this.localPort,
required this.host,
this.remoteUsername,
this.command = 'ssh',
List<String>? localSshOptions,
this.privateKeyFileName,
Bean? connectionBean,
}) : sshOptions = [
if (shouldIncludePrivateKey(privateKeyFileName))
..._optionsWithPrivateKey,
...optionsWithPrivateKey,
...(localSshOptions ?? [])
] {
this.connectionBean = connectionBean;
Expand Down
50 changes: 49 additions & 1 deletion packages/noports_core/test/sshnp_params/sshnp_result_test.dart
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
void main() {}
import 'package:noports_core/sshnp.dart';
import 'package:test/test.dart';

void main() {
group('SSHNPResult', () {
group('Subclass Confirmation', () {
test('SSHNPSuccess test', () {
expect(SSHNPSuccess(), isA<SSHNPResult>());
});
test('SSHNPCommand test', () {
final res = SSHNPCommand(host: 'localhost', localPort: 22);
expect(res, isA<SSHNPSuccess>());
});
test('SSHNPNoOpSuccess test', () {
final res = SSHNPNoOpSuccess();
expect(res, isA<SSHNPResult>());
expect(res, isA<SSHNPSuccess>());
});
test('SSHNPFailure test', () {
expect(SSHNPFailure(), isA<SSHNPResult>());
});
test('SSHNPError test', () {
final res = SSHNPError('error message');
expect(res, isA<SSHNPResult>());
expect(res, isA<SSHNPFailure>());
});
});
group('SSHNPCommand', () {
test('toString() test', () {
final command = SSHNPCommand(
localPort: 22,
host: 'localhost',
remoteUsername: 'myUsername',
localSshOptions: ['-L 127.0.0.1:8080:127.0.0.1:80'],
privateKeyFileName: '~/.ssh/myPrivateKeyFile',
);
expect(
command.toString(),
equals(
'ssh -p 22 ${optionsWithPrivateKey.join(' ')} '
'-L 127.0.0.1:8080:127.0.0.1:80 '
'myUsername@localhost '
'-i ~/.ssh/myPrivateKeyFile',
),
);
});
});
});
}

0 comments on commit 3873d70

Please sign in to comment.