OSDN Git Service

ticket #363
[ultramonkey-l7/ultramonkey-l7-v3.git] / l7directord / t / 11_child_cmd.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 => 6;
9 use Socket;
10 use Socket6;
11
12 L7lib::chdir();
13 L7lib::comment_out();
14 require './l7directord';
15 override();
16
17 our @system_wrapper_args = ();
18 our @system_wrapper_returns = ();
19 #...............................................
20 # test start
21 #   - ld_cmd_children
22 {
23     set_default();
24     local @system_wrapper_args = ();
25     local @system_wrapper_returns = ();
26     ld_cmd_children();
27     is_deeply \@system_wrapper_args, [], 'ld_cmd_children - no execute';
28 }
29 {
30     set_default();
31     local @system_wrapper_args = ();
32     local @system_wrapper_returns = ();
33     $main::CONFIG{execute} = { subconf1 => 1, subconf2 => 1 };
34     ld_cmd_children();
35     is_deeply \@system_wrapper_args, [], 'ld_cmd_children - exists execute, but no command';
36 }
37 {
38     set_default();
39     local @system_wrapper_args = ();
40     local @system_wrapper_returns = ();
41     $main::CONFIG{execute} = { subconf1 => 1, subconf2 => 1 };
42     ld_cmd_children('start');
43     is_deeply \@system_wrapper_args, ['l7directord subconf1 start', 'l7directord subconf2 start'],
44         'ld_cmd_children - exists execute and command';
45 }
46 {
47     set_default();
48     local @system_wrapper_args = ();
49     local @system_wrapper_returns = ();
50     $main::CONFIG{execute} = { subconf1 => 1, subconf2 => 1 };
51     ld_cmd_children('start', {});
52     is_deeply \@system_wrapper_args, [], 'ld_cmd_children - specified empty config';
53 }
54 {
55     set_default();
56     local @system_wrapper_args = ();
57     local @system_wrapper_returns = ();
58     my $execute = { subconf1 => 1, subconf2 => 1 };
59     ld_cmd_children(undef, $execute);
60     is_deeply \@system_wrapper_args, [], 'ld_cmd_children - specified config but not exist command';
61 }
62 {
63     set_default();
64     local @system_wrapper_args = ();
65     local @system_wrapper_returns = ();
66     my $execute = { subconf1 => 1, subconf2 => 1 };
67     ld_cmd_children('start', $execute);
68     is_deeply \@system_wrapper_args, ['l7directord subconf1 start', 'l7directord subconf2 start'],
69         'ld_cmd_children - specified config and exists command';
70 }
71 # test end
72 #...............................................
73
74 L7lib::comment_in();
75
76 sub set_default {
77     %main::CONFIG = %main::GLOBAL;
78     $main::PROC_ENV{l7directord} = 'l7directord';
79 }
80 sub override {
81     *system_wrapper = \&__system_wrapper;
82     *ld_log = \&__ld_log;
83 }
84 sub __system_wrapper {
85     push @system_wrapper_args, @_;
86     return shift @system_wrapper_returns;
87 }
88 sub __ld_log {
89 }