diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-07-08 18:15:41 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-07-08 18:15:41 +0300 |
commit | 32b6c6394dc6a789826bd51575d9703bb4097f70 (patch) | |
tree | ec851b9e9b90b74546df99b878b2dfeb3c2cc445 | |
parent | 10897f8a984a6dbc511403ca942fb8c7a8883349 (diff) | |
download | config-haproxy-32b6c6394dc6a789826bd51575d9703bb4097f70.tar.gz config-haproxy-32b6c6394dc6a789826bd51575d9703bb4097f70.tar.bz2 |
Add testsuite
-rw-r--r-- | lib/Config/HAProxy.pm | 3 | ||||
-rw-r--r-- | t/Test/HAProxy.pm | 23 | ||||
-rw-r--r-- | t/format.t | 106 | ||||
-rw-r--r-- | t/select.t | 43 |
4 files changed, 175 insertions, 0 deletions
diff --git a/lib/Config/HAProxy.pm b/lib/Config/HAProxy.pm index 45b0f1f..7938bcb 100644 --- a/lib/Config/HAProxy.pm +++ b/lib/Config/HAProxy.pm | |||
@@ -13,6 +13,8 @@ use File::Temp qw(tempfile); | |||
13 | use File::stat; | 13 | use File::stat; |
14 | use Carp; | 14 | use Carp; |
15 | 15 | ||
16 | our $VERSION = '1.00'; | ||
17 | |||
16 | my %sections = ( | 18 | my %sections = ( |
17 | global => 1, | 19 | global => 1, |
18 | defaults => 1, | 20 | defaults => 1, |
@@ -79,6 +81,7 @@ sub parse { | |||
79 | } | 81 | } |
80 | $self->pop; | 82 | $self->pop; |
81 | close $fh; | 83 | close $fh; |
84 | return $self; | ||
82 | } | 85 | } |
83 | 86 | ||
84 | sub reset { | 87 | sub reset { |
diff --git a/t/Test/HAProxy.pm b/t/Test/HAProxy.pm new file mode 100644 index 0000000..b5b8a19 --- /dev/null +++ b/t/Test/HAProxy.pm | |||
@@ -0,0 +1,23 @@ | |||
1 | package Test::HAProxy; | ||
2 | use strict; | ||
3 | use warnings; | ||
4 | use parent 'Config::HAProxy'; | ||
5 | use File::Basename; | ||
6 | use File::Temp; | ||
7 | use autodie; | ||
8 | |||
9 | sub new { | ||
10 | my $class = shift; | ||
11 | |||
12 | my $file = new File::Temp; | ||
13 | while (<main::DATA>) { | ||
14 | print $file $_; | ||
15 | } | ||
16 | close $file; | ||
17 | $class->SUPER::new($file->filename)->parse; | ||
18 | } | ||
19 | |||
20 | 1; | ||
21 | |||
22 | |||
23 | |||
diff --git a/t/format.t b/t/format.t new file mode 100644 index 0000000..06b9884 --- /dev/null +++ b/t/format.t | |||
@@ -0,0 +1,106 @@ | |||
1 | # -*- perl -*- | ||
2 | use lib qw(t lib); | ||
3 | use strict; | ||
4 | use warnings; | ||
5 | use Test::More; | ||
6 | use autodie; | ||
7 | |||
8 | BEGIN { | ||
9 | plan tests => 6; | ||
10 | use_ok('Test::HAProxy'); | ||
11 | } | ||
12 | |||
13 | my $hp = new Test::HAProxy; | ||
14 | isa_ok($hp,'Test::HAProxy'); | ||
15 | |||
16 | my $s; | ||
17 | open(my $fh, '>', \$s); | ||
18 | $hp->write($fh); | ||
19 | close $fh; | ||
20 | |||
21 | is($s, q{global | ||
22 | # comment | ||
23 | log /dev/log daemon | ||
24 | user haproxy | ||
25 | group haproxy | ||
26 | defaults | ||
27 | log global | ||
28 | mode http | ||
29 | frontend in | ||
30 | mode http | ||
31 | bind :::80 v4v6 | ||
32 | backend out | ||
33 | server localhost http://127.0.0.1 | ||
34 | }, 'default write'); | ||
35 | |||
36 | open($fh, '>', \$s); | ||
37 | $hp->write($fh, indent => 2); | ||
38 | close $fh; | ||
39 | |||
40 | is($s, q{global | ||
41 | # comment | ||
42 | log /dev/log daemon | ||
43 | user haproxy | ||
44 | group haproxy | ||
45 | defaults | ||
46 | log global | ||
47 | mode http | ||
48 | frontend in | ||
49 | mode http | ||
50 | bind :::80 v4v6 | ||
51 | backend out | ||
52 | server localhost http://127.0.0.1 | ||
53 | }, 'reindent'); | ||
54 | |||
55 | open($fh, '>', \$s); | ||
56 | $hp->write($fh, indent => 2, reindent_comments => 1); | ||
57 | close $fh; | ||
58 | |||
59 | is($s, q{global | ||
60 | # comment | ||
61 | log /dev/log daemon | ||
62 | user haproxy | ||
63 | group haproxy | ||
64 | defaults | ||
65 | log global | ||
66 | mode http | ||
67 | frontend in | ||
68 | mode http | ||
69 | bind :::80 v4v6 | ||
70 | backend out | ||
71 | server localhost http://127.0.0.1 | ||
72 | }, 'reindent comments'); | ||
73 | |||
74 | open($fh, '>', \$s); | ||
75 | $hp->write($fh, indent => 4, tabstop => [ 10, 24 ]); | ||
76 | close $fh; | ||
77 | |||
78 | is($s, q{global | ||
79 | # comment | ||
80 | log /dev/log daemon | ||
81 | user haproxy | ||
82 | group haproxy | ||
83 | defaults | ||
84 | log global | ||
85 | mode http | ||
86 | frontend in | ||
87 | mode http | ||
88 | bind :::80 v4v6 | ||
89 | backend out | ||
90 | server localhost http://127.0.0.1 | ||
91 | }, 'tabstops'); | ||
92 | |||
93 | __DATA__ | ||
94 | global | ||
95 | # comment | ||
96 | log /dev/log daemon | ||
97 | user haproxy | ||
98 | group haproxy | ||
99 | defaults | ||
100 | log global | ||
101 | mode http | ||
102 | frontend in | ||
103 | mode http | ||
104 | bind :::80 v4v6 | ||
105 | backend out | ||
106 | server localhost http://127.0.0.1 | ||
diff --git a/t/select.t b/t/select.t new file mode 100644 index 0000000..0be1c9c --- /dev/null +++ b/t/select.t | |||
@@ -0,0 +1,43 @@ | |||
1 | # -*- perl -*- | ||
2 | use lib qw(t lib); | ||
3 | use strict; | ||
4 | use warnings; | ||
5 | use Test::More; | ||
6 | use autodie; | ||
7 | |||
8 | BEGIN { | ||
9 | plan tests => 4; | ||
10 | use_ok('Test::HAProxy'); | ||
11 | } | ||
12 | |||
13 | my $hp = new Test::HAProxy; | ||
14 | isa_ok($hp,'Test::HAProxy'); | ||
15 | |||
16 | is(join(',', map { $_->arg(0) } $hp->select ( name => 'frontend' )), | ||
17 | 'in,ins', | ||
18 | 'simple select'); | ||
19 | |||
20 | is(join(',', map { $_->arg(0) } $hp->select ( name => 'frontend', | ||
21 | arg => { n => 0, v => 'in' } )), | ||
22 | 'in', | ||
23 | 'complex select'); | ||
24 | |||
25 | |||
26 | __DATA__ | ||
27 | global | ||
28 | log /dev/log daemon | ||
29 | user haproxy | ||
30 | group haproxy | ||
31 | defaults | ||
32 | log global | ||
33 | mode http | ||
34 | frontend in | ||
35 | mode http | ||
36 | bind :::80 v4v6 | ||
37 | backend out | ||
38 | server localhost http://127.0.0.1 | ||
39 | frontend ins | ||
40 | mode https | ||
41 | bind :::443 v4v6 | ||
42 | |||
43 | |||