summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-07-08 18:15:41 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-07-08 18:15:41 +0300
commit32b6c6394dc6a789826bd51575d9703bb4097f70 (patch)
treeec851b9e9b90b74546df99b878b2dfeb3c2cc445
parent10897f8a984a6dbc511403ca942fb8c7a8883349 (diff)
downloadconfig-haproxy-32b6c6394dc6a789826bd51575d9703bb4097f70.tar.gz
config-haproxy-32b6c6394dc6a789826bd51575d9703bb4097f70.tar.bz2
Add testsuite
-rw-r--r--lib/Config/HAProxy.pm3
-rw-r--r--t/Test/HAProxy.pm23
-rw-r--r--t/format.t106
-rw-r--r--t/select.t43
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);
13use File::stat; 13use File::stat;
14use Carp; 14use Carp;
15 15
16our $VERSION = '1.00';
17
16my %sections = ( 18my %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
84sub reset { 87sub 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 @@
1package Test::HAProxy;
2use strict;
3use warnings;
4use parent 'Config::HAProxy';
5use File::Basename;
6use File::Temp;
7use autodie;
8
9sub 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
201;
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 -*-
2use lib qw(t lib);
3use strict;
4use warnings;
5use Test::More;
6use autodie;
7
8BEGIN {
9 plan tests => 6;
10 use_ok('Test::HAProxy');
11}
12
13my $hp = new Test::HAProxy;
14isa_ok($hp,'Test::HAProxy');
15
16my $s;
17open(my $fh, '>', \$s);
18$hp->write($fh);
19close $fh;
20
21is($s, q{global
22# comment
23 log /dev/log daemon
24 user haproxy
25 group haproxy
26defaults
27 log global
28 mode http
29frontend in
30 mode http
31 bind :::80 v4v6
32backend out
33 server localhost http://127.0.0.1
34}, 'default write');
35
36open($fh, '>', \$s);
37$hp->write($fh, indent => 2);
38close $fh;
39
40is($s, q{global
41# comment
42 log /dev/log daemon
43 user haproxy
44 group haproxy
45defaults
46 log global
47 mode http
48frontend in
49 mode http
50 bind :::80 v4v6
51backend out
52 server localhost http://127.0.0.1
53}, 'reindent');
54
55open($fh, '>', \$s);
56$hp->write($fh, indent => 2, reindent_comments => 1);
57close $fh;
58
59is($s, q{global
60 # comment
61 log /dev/log daemon
62 user haproxy
63 group haproxy
64defaults
65 log global
66 mode http
67frontend in
68 mode http
69 bind :::80 v4v6
70backend out
71 server localhost http://127.0.0.1
72}, 'reindent comments');
73
74open($fh, '>', \$s);
75$hp->write($fh, indent => 4, tabstop => [ 10, 24 ]);
76close $fh;
77
78is($s, q{global
79# comment
80 log /dev/log daemon
81 user haproxy
82 group haproxy
83defaults
84 log global
85 mode http
86frontend in
87 mode http
88 bind :::80 v4v6
89backend out
90 server localhost http://127.0.0.1
91}, 'tabstops');
92
93__DATA__
94global
95# comment
96 log /dev/log daemon
97 user haproxy
98 group haproxy
99defaults
100 log global
101 mode http
102frontend in
103 mode http
104 bind :::80 v4v6
105backend 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 -*-
2use lib qw(t lib);
3use strict;
4use warnings;
5use Test::More;
6use autodie;
7
8BEGIN {
9 plan tests => 4;
10 use_ok('Test::HAProxy');
11}
12
13my $hp = new Test::HAProxy;
14isa_ok($hp,'Test::HAProxy');
15
16is(join(',', map { $_->arg(0) } $hp->select ( name => 'frontend' )),
17 'in,ins',
18 'simple select');
19
20is(join(',', map { $_->arg(0) } $hp->select ( name => 'frontend',
21 arg => { n => 0, v => 'in' } )),
22 'in',
23 'complex select');
24
25
26__DATA__
27global
28 log /dev/log daemon
29 user haproxy
30 group haproxy
31defaults
32 log global
33 mode http
34frontend in
35 mode http
36 bind :::80 v4v6
37backend out
38 server localhost http://127.0.0.1
39frontend ins
40 mode https
41 bind :::443 v4v6
42
43

Return to:

Send suggestions and report system problems to the System administrator.