OSDN Git Service

Fixed chkconfig option
[ultramonkey-l7/ultramonkey-l7-v2.git] / l7directord / t / 30_status.t
1 use strict;
2 use warnings;
3 no warnings qw(redefine once);
4 use lib qw(t/lib lib);
5 use subs qw(print);
6 use Cwd;
7 use L7lib;
8 use Test::More tests => 21;
9
10 L7lib::chdir();
11 L7lib::comment_out();
12 require './l7directord';
13 override();
14
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 = ();
21
22 #...............................................
23 # test start
24 #   - service_set
25 #   - _service_up
26 #   - _service_down
27 #   - _status_up
28 #   - _status_down
29 #   - get_status
30 {
31     set_default();
32     my $v_r_list = undef;
33     my $state = undef;
34     service_set($v_r_list, $state);
35     pass 'service_set - state is undef';
36 }
37 {
38     set_default();
39     my $v_r_list = undef;
40     my $state = 'up';
41     service_set($v_r_list, $state);
42     pass 'service_set - v_r_list is undef(1)';
43 }
44 {
45     set_default();
46     my $v_r_list = undef;
47     my $state = 'down';
48     service_set($v_r_list, $state);
49     pass 'service_set - v_r_list is undef(2)';
50 }
51 {
52     local @get_health_check_id_str_args    = ();
53     local @get_health_check_id_str_returns = ('id1');
54     set_default();
55     my $v_r_list = [ ['v', 'r'] ];
56     my $state = 'up';
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';
60 }
61 {
62     local @get_health_check_id_str_args    = ();
63     local @get_health_check_id_str_returns = ('id2');
64     set_default();
65     my $v_r_list = [ ['v', 'r'] ];
66     my $state = 'down';
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';
70 }
71 {
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 = ();
76     set_default();
77     my $v_r_list = [ ['v', 'r'] ];
78     my $state = 'up';
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';
85 }
86 {
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 = ();
91     set_default();
92     my $v_r_list = [ ['v', 'r'] ];
93     my $state = 'down';
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';
100 }
101 {
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 = ();
106     set_default();
107     my $v_r_list = [ ['v', 'r'] ];
108     my $state = 'up';
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';
114 }
115 {
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 = ();
120     set_default();
121     my $v_r_list = [ ['v', 'r'] ];
122     my $state = 'down';
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';
128 }
129 # test end
130 #...............................................
131
132 L7lib::comment_in();
133
134 sub set_default {
135 }
136 sub override {
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;
143 }
144 sub __get_health_check_id_str {
145     push @get_health_check_id_str_args, [@_];
146     return shift @get_health_check_id_str_returns;
147 }
148 sub __fallback_on {
149     push @fallback_on_args, @_;
150 }
151 sub __fallback_off {
152     push @fallback_off_args, @_;
153 }
154 sub ___restore_service {
155     push @__restore_service_args, @_;
156 }
157 sub ___remove_service {
158     push @__remove_service_args, @_;
159 }
160 sub __ld_log {
161 }