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
@@ -10,12 +10,14 @@ use Config::HAProxy::Node::Empty;
use Text::ParseWords;
use File::Basename;
use File::Temp qw(tempfile);
use File::stat;
use Carp;
+our $VERSION = '1.00';
+
my %sections = (
global => 1,
defaults => 1,
frontend => 1,
backend => 1,
);
@@ -76,12 +78,13 @@ sub parse {
orig => $orig,
locus => $locus));
}
}
$self->pop;
close $fh;
+ return $self;
}
sub reset {
my $self = shift;
$self->{_stack} = [ new Config::HAProxy::Node::Root() ];
}
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 @@
+package Test::HAProxy;
+use strict;
+use warnings;
+use parent 'Config::HAProxy';
+use File::Basename;
+use File::Temp;
+use autodie;
+
+sub new {
+ my $class = shift;
+
+ my $file = new File::Temp;
+ while (<main::DATA>) {
+ print $file $_;
+ }
+ close $file;
+ $class->SUPER::new($file->filename)->parse;
+}
+
+1;
+
+
+
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 @@
+# -*- perl -*-
+use lib qw(t lib);
+use strict;
+use warnings;
+use Test::More;
+use autodie;
+
+BEGIN {
+ plan tests => 6;
+ use_ok('Test::HAProxy');
+}
+
+my $hp = new Test::HAProxy;
+isa_ok($hp,'Test::HAProxy');
+
+my $s;
+open(my $fh, '>', \$s);
+$hp->write($fh);
+close $fh;
+
+is($s, q{global
+# comment
+ log /dev/log daemon
+ user haproxy
+ group haproxy
+defaults
+ log global
+ mode http
+frontend in
+ mode http
+ bind :::80 v4v6
+backend out
+ server localhost http://127.0.0.1
+}, 'default write');
+
+open($fh, '>', \$s);
+$hp->write($fh, indent => 2);
+close $fh;
+
+is($s, q{global
+# comment
+ log /dev/log daemon
+ user haproxy
+ group haproxy
+defaults
+ log global
+ mode http
+frontend in
+ mode http
+ bind :::80 v4v6
+backend out
+ server localhost http://127.0.0.1
+}, 'reindent');
+
+open($fh, '>', \$s);
+$hp->write($fh, indent => 2, reindent_comments => 1);
+close $fh;
+
+is($s, q{global
+ # comment
+ log /dev/log daemon
+ user haproxy
+ group haproxy
+defaults
+ log global
+ mode http
+frontend in
+ mode http
+ bind :::80 v4v6
+backend out
+ server localhost http://127.0.0.1
+}, 'reindent comments');
+
+open($fh, '>', \$s);
+$hp->write($fh, indent => 4, tabstop => [ 10, 24 ]);
+close $fh;
+
+is($s, q{global
+# comment
+ log /dev/log daemon
+ user haproxy
+ group haproxy
+defaults
+ log global
+ mode http
+frontend in
+ mode http
+ bind :::80 v4v6
+backend out
+ server localhost http://127.0.0.1
+}, 'tabstops');
+
+__DATA__
+global
+# comment
+ log /dev/log daemon
+ user haproxy
+ group haproxy
+defaults
+ log global
+ mode http
+frontend in
+ mode http
+ bind :::80 v4v6
+backend out
+ 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 @@
+# -*- perl -*-
+use lib qw(t lib);
+use strict;
+use warnings;
+use Test::More;
+use autodie;
+
+BEGIN {
+ plan tests => 4;
+ use_ok('Test::HAProxy');
+}
+
+my $hp = new Test::HAProxy;
+isa_ok($hp,'Test::HAProxy');
+
+is(join(',', map { $_->arg(0) } $hp->select ( name => 'frontend' )),
+ 'in,ins',
+ 'simple select');
+
+is(join(',', map { $_->arg(0) } $hp->select ( name => 'frontend',
+ arg => { n => 0, v => 'in' } )),
+ 'in',
+ 'complex select');
+
+
+__DATA__
+global
+ log /dev/log daemon
+ user haproxy
+ group haproxy
+defaults
+ log global
+ mode http
+frontend in
+ mode http
+ bind :::80 v4v6
+backend out
+ server localhost http://127.0.0.1
+frontend ins
+ mode https
+ bind :::443 v4v6
+
+

Return to:

Send suggestions and report system problems to the System administrator.