3 no warnings qw(redefine once);
8 use Test::More tests => 21;
12 require './l7directord';
15 our @get_health_check_id_str_args = ();
16 our @get_health_check_id_str_returns = ();
17 our @fallback_on_args = ();
18 our @fallback_off_args = ();
19 our @__restore_service_args = ();
20 our @__remove_service_args = ();
22 #...............................................
34 service_set($v_r_list, $state);
35 pass 'service_set - state is undef';
41 service_set($v_r_list, $state);
42 pass 'service_set - v_r_list is undef(1)';
48 service_set($v_r_list, $state);
49 pass 'service_set - v_r_list is undef(2)';
52 local @get_health_check_id_str_args = ();
53 local @get_health_check_id_str_returns = ('id1');
55 my $v_r_list = [ ['v', 'r'] ];
57 local $main::HEALTH_CHECK{id1}{status} = $main::SERVICE_UP;
58 service_set($v_r_list, $state);
59 is_deeply \@get_health_check_id_str_args, [['v', 'r']], 'service_set - set up, but already up';
62 local @get_health_check_id_str_args = ();
63 local @get_health_check_id_str_returns = ('id2');
65 my $v_r_list = [ ['v', 'r'] ];
67 local $main::HEALTH_CHECK{id2}{status} = $main::SERVICE_DOWN;
68 service_set($v_r_list, $state);
69 is_deeply \@get_health_check_id_str_args, [['v', 'r']], 'service_set - set down, but already down';
72 local @get_health_check_id_str_args = ();
73 local @get_health_check_id_str_returns = ('id1', 'id1');
74 local @fallback_off_args = ();
75 local @__restore_service_args = ();
77 my $v_r_list = [ ['v', 'r'] ];
79 local $main::HEALTH_CHECK{id1}{status} = $main::SERVICE_DOWN;
80 service_set($v_r_list, $state);
81 is_deeply \@get_health_check_id_str_args, [['v', 'r'], ['v', 'r']], 'service_set - set up';
82 is_deeply \@fallback_off_args, ['v'], 'service_set - set up - fallback off args';
83 is_deeply \@__restore_service_args, ['v', 'r', 'real'], 'service_set - set up - restore service args';
84 is $main::HEALTH_CHECK{id1}{status}, $main::SERVICE_UP, 'service_set - status is changed to up';
87 local @get_health_check_id_str_args = ();
88 local @get_health_check_id_str_returns = ('id2', 'id2');
89 local @fallback_on_args = ();
90 local @__remove_service_args = ();
92 my $v_r_list = [ ['v', 'r'] ];
94 local $main::HEALTH_CHECK{id2}{status} = $main::SERVICE_UP;
95 service_set($v_r_list, $state);
96 is_deeply \@get_health_check_id_str_args, [['v', 'r'], ['v', 'r']], 'service_set - set down';
97 is_deeply \@fallback_on_args, ['v'], 'service_set - set up - fallback on args';
98 is_deeply \@__remove_service_args, ['v', 'r', 'real'], 'service_set - set up - remove service args';
99 is $main::HEALTH_CHECK{id2}{status}, $main::SERVICE_DOWN, 'service_set - status is changed to down';
102 local @get_health_check_id_str_args = ();
103 local @get_health_check_id_str_returns = ('id1', 'id1');
104 local @fallback_off_args = ();
105 local @__restore_service_args = ();
107 my $v_r_list = [ ['v', 'r'] ];
109 service_set($v_r_list, $state);
110 is_deeply \@get_health_check_id_str_args, [['v', 'r'], ['v', 'r']], 'service_set - set up, but not defined id';
111 is_deeply \@fallback_off_args, ['v'], 'service_set - set up - fallback off args';
112 is_deeply \@__restore_service_args, ['v', 'r', 'real'], 'service_set - set up - restore service args';
113 is $main::HEALTH_CHECK{id1}{status}, $main::SERVICE_UP, 'service_set - status is registerd as up';
116 local @get_health_check_id_str_args = ();
117 local @get_health_check_id_str_returns = ('id2', 'id2');
118 local @fallback_on_args = ();
119 local @__remove_service_args = ();
121 my $v_r_list = [ ['v', 'r'] ];
123 service_set($v_r_list, $state);
124 is_deeply \@get_health_check_id_str_args, [['v', 'r'], ['v', 'r']], 'service_set - set down, but not defined id';
125 is_deeply \@fallback_on_args, ['v'], 'service_set - set up - fallback on args';
126 is_deeply \@__remove_service_args, ['v', 'r', 'real'], 'service_set - set up - remove service args';
127 is $main::HEALTH_CHECK{id2}{status}, $main::SERVICE_DOWN, 'service_set - status is registerd as down';
130 #...............................................
137 *ld_log = \&__ld_log;
138 *get_health_check_id_str = \&__get_health_check_id_str;
139 *fallback_on = \&__fallback_on;
140 *fallback_off = \&__fallback_off;
141 *_restore_service = \&___restore_service;
142 *_remove_service = \&___remove_service;
144 sub __get_health_check_id_str {
145 push @get_health_check_id_str_args, [@_];
146 return shift @get_health_check_id_str_returns;
149 push @fallback_on_args, @_;
152 push @fallback_off_args, @_;
154 sub ___restore_service {
155 push @__restore_service_args, @_;
157 sub ___remove_service {
158 push @__remove_service_args, @_;