forked from munin-monitoring/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmunin_master_node.t
118 lines (87 loc) · 2.64 KB
/
munin_master_node.t
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use warnings;
use strict;
use Munin::Master::Config;
use Test::More;
if ($ENV{TEST_MEDIUM}) {
plan tests => 9;
}
else {
plan skip_all => 'set TEST_MEDIUM to enable these tests';
}
use Test::MockModule;
use Test::MockObject::Extends;
use Test::Exception;
use Test::Differences;
use Data::Dumper;
use Munin::Common::Logger;
Munin::Common::Logger->_remove_default_logging;
use_ok('Munin::Master::Node');
sub setup {
my $node = Munin::Master::Node->new('127.0.0.1', 4949, 'node');
my $node_mock = Test::MockObject::Extends->new($node);
$node_mock->{configref} = Munin::Master::Config->instance();
$node_mock->{configref}{use_node_name} = 1;
$node_mock->mock('_node_write_single', sub {});
$node_mock->mock('_node_read_fast', sub {
my ($self) = @_;
return $self->_node_read();
});
return $node_mock;
}
### new
{
my $node = Munin::Master::Node->new();
isa_ok($node, 'Munin::Master::Node','Create a node object');
}
### _do_connect
{
my $node = setup();
$node->mock('_node_read_single', sub {
return '# munin node at foo.example.com'
});
my $inet = Test::MockModule->new('IO::Socket::INET6');
$inet->mock(new => sub { return {} });
$node->_do_connect();
is($node->{node_name}, 'foo.example.com','Node name is detected');
}
### _extract_name_from_greeting
{
my $node = Munin::Master::Node->new();
$node->_extract_name_from_greeting('# munin node at foo.example.com');
is($node->{node_name}, 'foo.example.com', 'Node name from new greeting');
$node->_extract_name_from_greeting('# lrrd client at foo.example.com');
is($node->{node_name}, 'foo.example.com', 'Node name from old greeting');
}
### negotiate_capabilities
{
my $node = setup();
$node->mock('_node_read_single', sub {
return 'cap multigraph';
});
my @res = $node->negotiate_capabilities();
is_deeply(\@res, ['multigraph'], 'Capabilities - single');
}
{
my $node = setup();
$node->mock('_node_read_single', sub {
return '# Unknown command. Try list, nodes, config, fetch, version or quit';
});
my @res = $node->negotiate_capabilities();
is_deeply(\@res, ['NA'], 'Capabilities - single');
}
{
my $node = setup();
$node->mock('_node_read_single', sub {
return ['cap bar baz foo'];
});
my @res = $node->negotiate_capabilities();
is_deeply(\@res, ['NA'], 'Capabilities - none');
}
### list_plugins
{
my $node = setup();
$node->mock('_node_read_single', sub { return 'foo bar baz'; });
$node->{node_name} = 'node';
my @res = $node->list_plugins();
is_deeply(\@res, [qw(foo bar baz)], 'List plugins');
}