From 4f27f3ea59baa6cfca0ac1df96b1dfedbd83706c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 2 Jan 2015 14:00:56 +0100 Subject: initial --- t/Makefile | 2 ++ t/delete.t | 28 +++++++++++++++++++ t/edit.t | 26 ++++++++++++++++++ t/get.t | 25 +++++++++++++++++ t/get_interactive.t | 25 +++++++++++++++++ t/get_where.t | 48 +++++++++++++++++++++++++++++++++ t/getfmt.t | 23 ++++++++++++++++ t/insert.t | 29 ++++++++++++++++++++ t/options_debug_verbose_quiet.t | 43 +++++++++++++++++++++++++++++ t/options_version.t | 28 +++++++++++++++++++ t/post.t | 41 ++++++++++++++++++++++++++++ t/post_as_array.t | 39 +++++++++++++++++++++++++++ t/post_interactive.t | 41 ++++++++++++++++++++++++++++ t/put.t | 60 +++++++++++++++++++++++++++++++++++++++++ t/update.t | 49 +++++++++++++++++++++++++++++++++ t/update_format.t | 37 +++++++++++++++++++++++++ t/view.t | 22 +++++++++++++++ 17 files changed, 566 insertions(+) create mode 100644 t/Makefile create mode 100644 t/delete.t create mode 100644 t/edit.t create mode 100644 t/get.t create mode 100644 t/get_interactive.t create mode 100644 t/get_where.t create mode 100644 t/getfmt.t create mode 100644 t/insert.t create mode 100644 t/options_debug_verbose_quiet.t create mode 100644 t/options_version.t create mode 100644 t/post.t create mode 100644 t/post_as_array.t create mode 100644 t/post_interactive.t create mode 100644 t/put.t create mode 100644 t/update.t create mode 100644 t/update_format.t create mode 100644 t/view.t (limited to 't') diff --git a/t/Makefile b/t/Makefile new file mode 100644 index 0000000..84197b2 --- /dev/null +++ b/t/Makefile @@ -0,0 +1,2 @@ +all: + MON_CONFIG=~/.mon-test.conf prove . diff --git a/t/delete.t b/t/delete.t new file mode 100644 index 0000000..7b4a9e6 --- /dev/null +++ b/t/delete.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest01.server.lan and host_name = footest01.server.lan and address = 127.0.0.1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest02.server.lan and host_name = footest02.server.lan and address = 127.0.0.1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor delete host where name like 'footest01.server.lan'`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +$json = decode_json `./mon --nocolor delete host where name like 'footest02.server.lan'`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +$json = decode_json `./mon --nocolor get host where name matches 'footest..\\.server\\.lan'`; +cmp_ok(scalar @$json, 'eq', 0, 'Testing get after delete'); + +done_testing(); diff --git a/t/edit.t b/t/edit.t new file mode 100644 index 0000000..c58bccb --- /dev/null +++ b/t/edit.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; +my $ret; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$ret = `EDITOR=/bin/true ./mon --nocolor edit host where name like footest.server.lan`; +cmp_ok($ret, 'eq', '', 'Testing edit'); + +$ret = `EDITOR=/bin/true ./mon --nocolor edit host where name like footest.server.lan`; +cmp_ok($ret, 'eq', '', 'Testing edit'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +done_testing(); diff --git a/t/get.t b/t/get.t new file mode 100644 index 0000000..85ae878 --- /dev/null +++ b/t/get.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get'); + +$json = decode_json `./mon --nocolor get host`; +cmp_ok(scalar @$json, '>', '1', 'Testing get'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +done_testing(); diff --git a/t/get_interactive.t b/t/get_interactive.t new file mode 100644 index 0000000..85ae878 --- /dev/null +++ b/t/get_interactive.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get'); + +$json = decode_json `./mon --nocolor get host`; +cmp_ok(scalar @$json, '>', '1', 'Testing get'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +done_testing(); diff --git a/t/get_where.t b/t/get_where.t new file mode 100644 index 0000000..58c0465 --- /dev/null +++ b/t/get_where.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; + +for my $num (1..10) { + $json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest${num}.server.lan and host_name = footest${num}.server.lan and address = 127.0.0.${num}`; + cmp_ok($json->{message}, 'eq', '1 changes successfully commited', "Testing insert $num"); +} + +$json = decode_json `./mon --nocolor get host where name like footest1.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get like'); + +$json = decode_json `./mon --nocolor get host where name matches footest1.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get matches'); + +$json = decode_json `./mon --nocolor get host where name nmatches footest1.server.lan and name like footest`; +cmp_ok(scalar @$json, '==', '9', 'Testing get nmatches'); + +$json = decode_json `./mon --nocolor get host where name eq footest2.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.2', 'Testing get eq'); + +$json = decode_json `./mon --nocolor get host where name ne footest1.server.lan and name like footest`; +cmp_ok(scalar @$json, '==', '9', 'Testing get ne'); + +$json = decode_json `./mon --nocolor get host where name lt 2 and name like footest`; +cmp_ok(scalar @$json, '==', '1', 'Testing get lt'); + +$json = decode_json `./mon --nocolor get host where name le 2 and name like footest`; +cmp_ok(scalar @$json, '==', '2', 'Testing get le'); + +$json = decode_json `./mon --nocolor get host where name gt 2 and name like footest`; +cmp_ok(scalar @$json, '==', '8', 'Testing get gt'); + +$json = decode_json `./mon --nocolor get host where name ge 2 and name like footest`; +cmp_ok(scalar @$json, '==', '9', 'Testing get ge'); + +$json = decode_json `./mon --nocolor delete host where name like footest and host_name like server.lan`; +cmp_ok($json->{message}, 'eq', '10 changes successfully commited', 'Testing delete'); + +done_testing(); diff --git a/t/getfmt.t b/t/getfmt.t new file mode 100644 index 0000000..b696390 --- /dev/null +++ b/t/getfmt.t @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; +my $res; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$res = `./mon --nocolor getfmt 'Foo:\$host_name' host where name like footest.server.lan`; +like($res, qr/Foo:footest.server.lan/, 'Testing getfmt'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +done_testing(); diff --git a/t/insert.t b/t/insert.t new file mode 100644 index 0000000..451e0c4 --- /dev/null +++ b/t/insert.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1 and _FOO = foo`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor -m get host where name like footest.server.lan`; +cmp_ok($json->[0]{_FOO}, 'eq', 'foo', 'Testing get after a put'); + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.2`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.2', 'Testing get after a put'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +done_testing(); + diff --git a/t/options_debug_verbose_quiet.t b/t/options_debug_verbose_quiet.t new file mode 100644 index 0000000..4ba69f8 --- /dev/null +++ b/t/options_debug_verbose_quiet.t @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +# Testing --debug, -D, --verbose, -v and --quiet, -q + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; +my $ret; + +$ret = `./mon -q insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1`; +cmp_ok($ret, 'eq', '', 'Testing quiet insert'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get'); + +$json = decode_json `./mon --nocolor get host`; +cmp_ok(scalar @$json, '>', '1', 'Testing get'); + +$ret = `./mon -D --nocolor get host >/dev/null 2>/tmp/montest.tmp;cat /tmp/montest.tmp`; +like($ret, qr/MON::Filter/, 'Testing debug get'); + +$ret = `./mon --debug --nocolor get host >/dev/null 2>/tmp/montest.tmp;cat /tmp/montest.tmp`; +like($ret, qr/MON::Filter/, 'Testing debug get'); + +$ret = `./mon -v --nocolor get host >/dev/null 2>/tmp/montest.tmp;cat /tmp/montest.tmp`; +like($ret, qr/Reading config/, 'Testing verbose get'); + +$ret = `./mon --verbose --nocolor get host >/dev/null 2>/tmp/montest.tmp;cat /tmp/montest.tmp`; +like($ret, qr/Reading config/, 'Testing verbose get'); + +$ret = `./mon --quiet --nocolor delete host where name like footest.server.lan`; +cmp_ok($ret, 'eq', '', 'Testing quiet delete'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok(scalar @$json, '<', '1', 'Testing get'); + +done_testing(); diff --git a/t/options_version.t b/t/options_version.t new file mode 100644 index 0000000..bfe45a1 --- /dev/null +++ b/t/options_version.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +# Testing --version, -V + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; +my $ret; + +my $version = `cat .version`; +chomp $version; + +$ret = `./mon --version`; +chomp $ret; +cmp_ok($ret, 'eq', $version, 'Testing version'); + +$ret = `./mon -V`; +chomp $ret; +cmp_ok($ret, 'eq', $version, 'Testing version'); + + +done_testing(); diff --git a/t/post.t b/t/post.t new file mode 100644 index 0000000..b27f2b5 --- /dev/null +++ b/t/post.t @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use File::Temp qw(tempfile); +use JSON; +use Test::More; + +my $json1 = < '.json' ); +print $jsonfh1 $json1; + +my $json; + +$json = decode_json `./mon --nocolor post host < $jsonfile1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing post'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +unlink $jsonfile1; + +done_testing(); diff --git a/t/post_as_array.t b/t/post_as_array.t new file mode 100644 index 0000000..ede7b49 --- /dev/null +++ b/t/post_as_array.t @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use File::Temp qw(tempfile); +use JSON; +use Test::More; + +my $json1 = < '.json' ); +print $jsonfh1 $json1; + +my $json; + +$json = decode_json `./mon --nocolor post host < $jsonfile1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing post'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +unlink $jsonfile1; + +done_testing(); diff --git a/t/post_interactive.t b/t/post_interactive.t new file mode 100644 index 0000000..354d2b5 --- /dev/null +++ b/t/post_interactive.t @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use File::Temp qw(tempfile); +use JSON; +use Test::More; + +my $json1 = < '.json' ); +print $jsonfh1 $json1; + +my $json; + +$json = decode_json `./mon --nocolor post host \< $jsonfile1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing post'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +unlink $jsonfile1; + +done_testing(); diff --git a/t/put.t b/t/put.t new file mode 100644 index 0000000..9f07180 --- /dev/null +++ b/t/put.t @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use File::Temp qw(tempfile); +use JSON; +use Test::More; + +my $json1 = < '.json' ); +print $jsonfh1 $json1; + +my ($jsonfh2, $jsonfile2) = tempfile( undef, SUFFIX => '.json' ); +print $jsonfh2 $json2; + +my $json; + +$json = decode_json `./mon --nocolor post host < $jsonfile1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing post'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.1', 'Testing get'); + +$json = decode_json `./mon --nocolor put host < $jsonfile2`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing put'); + +$json = decode_json `./mon --nocolor get host where name like footest.server.lan`; +cmp_ok($json->[0]{address}, 'eq', '127.0.0.2', 'Testing get after a put'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +unlink $jsonfile1; +unlink $jsonfile2; + +done_testing(); diff --git a/t/update.t b/t/update.t new file mode 100644 index 0000000..1593371 --- /dev/null +++ b/t/update.t @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1 and _FOO = foo and _BAR = bar`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor update host delete _FOO where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing update ... delete'); + +$json = decode_json `./mon --nocolor -m get host where name like footest.server.lan`; +cmp_ok(exists $json->[0]{_FOO}, '==', 0, 'Testing get after a update'); +cmp_ok($json->[0]{_BAR}, 'eq', 'bar', 'Testing get after a update'); + +$json = decode_json `./mon --nocolor update host set _FOO = fuu where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing update ... set'); + +$json = decode_json `./mon --nocolor -m get host where name like footest.server.lan`; +cmp_ok($json->[0]{_FOO}, 'eq', 'fuu', 'Testing get after a update'); + +$json = decode_json `./mon --nocolor update host set _ONE = one and _TWO = two where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing update ... set with multiple objects'); + +$json = decode_json `./mon --nocolor -m get host where name like footest.server.lan`; +cmp_ok($json->[0]{_FOO}, 'eq', 'fuu', 'Testing get after a update'); +cmp_ok($json->[0]{_BAR}, 'eq', 'bar', 'Testing get after a update'); +cmp_ok($json->[0]{_ONE}, 'eq', 'one', 'Testing get after a update'); +cmp_ok($json->[0]{_TWO}, 'eq', 'two', 'Testing get after a update'); + +$json = decode_json `./mon --nocolor update host delete _FOO and _BAR where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing update ... delete with multiple arguments'); + +$json = decode_json `./mon --nocolor -m get host where name like footest.server.lan`; +cmp_ok(exists $json->[0]{_FOO}, '==', 0, 'Testing get after a update'); +cmp_ok(exists $json->[0]{_BAR}, '==', 0, 'Testing get after a update'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing put'); + +done_testing(); + diff --git a/t/update_format.t b/t/update_format.t new file mode 100644 index 0000000..248dd17 --- /dev/null +++ b/t/update_format.t @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my $json; + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest01.server.lan and host_name = footest01.server.lan and address = 127.0.0.1 and _FOO = foo and _BAR = bar`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest02.server.lan and host_name = footest02.server.lan and address = 127.0.0.1 and _FOO = foo and _BAR = bar`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$json = decode_json `./mon --nocolor -m update host set _BEER = '\@_FOO' and _PIZZA = '\$_BAR' and _COLA = '\${_FOO}foo\@{_BAR}bar' where name like footest and host_name like server.lan`; +cmp_ok($json->{message}, 'eq', '2 changes successfully commited', 'Testing expression in update ... set'); + +$json = decode_json `./mon --nocolor -m get host where name like footest and host_name like server.lan`; +cmp_ok($json->[0]{_BEER}, 'eq', 'foo', 'Testing get after a update'); +cmp_ok($json->[1]{_BEER}, 'eq', 'foo', 'Testing get after a update'); +cmp_ok($json->[0]{_PIZZA}, 'eq', 'bar', 'Testing get after a update'); +cmp_ok($json->[1]{_PIZZA}, 'eq', 'bar', 'Testing get after a update'); +cmp_ok($json->[0]{_COLA}, 'eq', 'foofoobarbar', 'Testing get after a update'); +cmp_ok($json->[1]{_COLA}, 'eq', 'foofoobarbar', 'Testing get after a update'); + +$json = decode_json `./mon --nocolor delete host where name like footest01.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing put'); + +$json = decode_json `./mon --nocolor delete host where name like footest02.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing put'); + +done_testing(); + diff --git a/t/view.t b/t/view.t new file mode 100644 index 0000000..5351b2c --- /dev/null +++ b/t/view.t @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use v5.10; + +use JSON; +use Test::More; + +chdir '..'; +my ($json, $out); + +$json = decode_json `./mon --nocolor insert host set use = generic-host and name = footest.server.lan and host_name = footest.server.lan and address = 127.0.0.1`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing insert'); + +$out = `PAGER=/bin/true ./mon --nocolor view host where name like footest.server.lan 2>&1`; +cmp_ok($out, 'eq', '', 'Testing view'); + +$json = decode_json `./mon --nocolor delete host where name like footest.server.lan`; +cmp_ok($json->{message}, 'eq', '1 changes successfully commited', 'Testing delete'); + +done_testing(); -- cgit v1.2.3