forked from NMSSH/NMSSH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NMSSHChannelTests.m
63 lines (48 loc) · 1.8 KB
/
NMSSHChannelTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#import "NMSSHChannelTests.h"
#import "ConfigHelper.h"
#import <NMSSH/NMSSH.h>
@interface NMSSHChannelTests () {
NSDictionary *settings;
NMSSHChannel *channel;
NMSSHSession *session;
}
@end
@implementation NMSSHChannelTests
// -----------------------------------------------------------------------------
// TEST SETUP
// -----------------------------------------------------------------------------
- (void)setUp {
settings = [ConfigHelper valueForKey:@"valid_password_protected_server"];
session = [NMSSHSession connectToHost:[settings objectForKey:@"host"]
withUsername:[settings objectForKey:@"user"]];
[session authenticateByPassword:[settings objectForKey:@"password"]];
assert([session isAuthorized]);
}
- (void)tearDown {
if (channel) {
[channel close];
channel = nil;
}
if (session) {
[session disconnect];
session = nil;
}
}
// -----------------------------------------------------------------------------
// SHELL EXECUTION TESTS
// -----------------------------------------------------------------------------
- (void)testCreatingChannelWorks {
STAssertNoThrow(channel = [[NMSSHChannel alloc] initWithSession:session],
@"Setting up channel does not throw exception");
}
- (void)testExecutingShellCommand {
channel = [[NMSSHChannel alloc] initWithSession:session];
NSError *error = nil;
STAssertNoThrow([channel execute:[settings objectForKey:@"execute_command"]
error:&error],
@"Execution should not throw an exception");
STAssertEqualObjects([channel lastResponse],
[settings objectForKey:@"execute_expected_response"],
@"Execution returns the expected response");
}
@end