summaryrefslogtreecommitdiffstats
path: root/t/03-write-to-termcast.t
blob: 1e505f20e5c09b09b427e8b3bcd892efa7a5c4af (plain) (blame)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use App::Termcast;
BEGIN {
    eval "use Test::TCP;";
    plan skip_all => "Test::TCP is required for this test" if $@;
    plan tests => 3;
}

test_tcp(
    client => sub {
        my $port = shift;
        my $tc = App::Termcast->new(
            host => '127.0.0.1', port => $port,
            user => 'test', password => 'tset');
        $tc->write_to_termcast('foo');
        ok(!$tc->meta->find_attribute_by_name('pty')->has_value($tc),
           "pty isn't created");
        sleep 1;
    },
    server => sub {
        my $port = shift;
        my $sock = IO::Socket::INET->new(LocalAddr => '127.0.0.1',
                                         LocalPort => $port,
                                         Listen    => 1);
        $sock->accept; # signal to the client that the port is available
        my $client = $sock->accept;
        my $login;
        $client->recv($login, 4096);
        my $auth_regexp = qr/^hello test tset\n\e\[H\x00.+?\xff\e\[H\e\[2J/;
        like($login, $auth_regexp, 'got the correct login info');
        $client->send("hello, test\n");

        my $buf;
        $client->recv($buf, 4096);
        is($buf, 'foo', 'wrote correctly');
    },
);