summaryrefslogtreecommitdiffstats
path: root/t/netstring.t
diff options
context:
space:
mode:
authorAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2016-06-21 02:42:25 +0200
committerAlexander Sulfrian <alex@spline.inf.fu-berlin.de>2016-06-21 02:42:25 +0200
commit339312c92a71a0943ae34aab27b1026bb3479d0d (patch)
treecea49efa50ec436b517a25dc1d1ff90f575e2f18 /t/netstring.t
parentd9ba41806745b830fd229b4cbcd8b5386203af27 (diff)
downloadsrs-339312c92a71a0943ae34aab27b1026bb3479d0d.tar.gz
srs-339312c92a71a0943ae34aab27b1026bb3479d0d.tar.bz2
srs-339312c92a71a0943ae34aab27b1026bb3479d0d.zip
Make subclasses of Net::Server
Spline::Socketmap is now a subclasses of Net::Server and Spline::Socketmap::Srs is a subclass of Spline::Socketmap. This way the Srs stuff is completly independent of the postfix-socketmap protocol handling. The config is located in the instances and configurable with Net::Server command line options or config file.
Diffstat (limited to 't/netstring.t')
-rw-r--r--t/netstring.t44
1 files changed, 44 insertions, 0 deletions
diff --git a/t/netstring.t b/t/netstring.t
new file mode 100644
index 0000000..de0b61e
--- /dev/null
+++ b/t/netstring.t
@@ -0,0 +1,44 @@
+use strict;
+use warnings;
+
+use Test::More tests => 11;
+use Test::Exception;
+
+BEGIN {
+ use_ok 'Spline::Socketmap', qw(
+ netstring_read
+ netstring_write
+ ) or BAIL_OUT;
+}
+
+sub output($) {
+ my $data = shift;
+
+ my $output;
+ open(my $fh, '>', \$output);
+ netstring_write($fh, $data);
+ return $output;
+}
+
+sub input($) {
+ my $data = shift;
+
+ open(my $fh, '<', \$data);
+ return netstring_read($fh);
+}
+
+# Netstring output
+is(output('test'), '4:test,', 'Netstring output');
+is(output(''), '0:,', 'Empty netstring output');
+is(output('. '), '2:. ,', 'Preserve spaces');
+
+# Netstring input
+is(input('4:test,'), 'test', 'Basic netstring input');
+is(input('0:,'), '', 'Empty netstring input');
+throws_ok { input('4:test') } qr/, missing/, 'Missing final ,';
+throws_ok { input('5:test') } qr/4 of 5 bytes/, 'Data too short';
+throws_ok { input('4test') } qr/Invalid length/, 'Format error';
+throws_ok { input('') } qr/Cannot read .* length/, 'Empty input';
+throws_ok { netstring_read('') } qr/Filehandle required/, 'No filehandle';
+
+# vim: set et ts=4: