File: connect-disconnect.t

package info (click to toggle)
libnet-stomp-perl 0.62-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: perl: 1,311; makefile: 7
file content (69 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download | duplicates (5)
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
64
65
66
67
68
69
use lib 't/lib';
use TestHelp;
use Net::Stomp::Frame;

my ($s,$fh)=mkstomp_testsocket();

my $frame;my $buffer='';
$fh->{written} = sub {
    $buffer .= $_[0];
    $frame = Net::Stomp::Frame->parse($buffer);
    $buffer='' if $frame;
    return length($_[0]);
};

subtest 'connect' => sub {
    $fh->{to_read} = sub {
        if ($frame) {
            return Net::Stomp::Frame->new({
                command => 'CONNECTED',
                headers => {session=>'foo'},
            })->as_string;
        }
        return '';
    };

    $s->connect({login=>'me'});

    cmp_deeply(
        $frame,
        all(
            isa('Net::Stomp::Frame'),
            methods(
                command => 'CONNECT',
                headers => {login=>'me'},
                body => undef,
            ),
        ),
        'connect frame sent',
    );
    cmp_deeply(
        $s,
        methods(
            session_id => 'foo',
            _connect_headers => { login => 'me' },
        ),
        'connection data received and stored',
    );
};

subtest 'disconnect' => sub {
    $frame='';
    $s->disconnect;

    cmp_deeply(
        $frame,
        all(
            isa('Net::Stomp::Frame'),
            methods(
                command => 'DISCONNECT',
                headers => {},
                body => undef,
            ),
        ),
        'disconnect frame sent',
    );
    ok(not(defined($s->select->{socket})),'socket was removed from select');
};

done_testing;