OSDN Git Service

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