Skip to content

Commit

Permalink
Merge 120285c into bf399dd
Browse files Browse the repository at this point in the history
  • Loading branch information
vpeil committed Oct 19, 2018
2 parents bf399dd + 120285c commit c37d176
Show file tree
Hide file tree
Showing 32 changed files with 513 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/LibreCat/Cmd/file_store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ sub _exists {

printf "$key %s\n", $ans ? "EXISTS" : "NOT_FOUND";

exit($ans ? 0 : 2);
$ans ? return 0 : return 2;
}

sub _get {
Expand Down
2 changes: 1 addition & 1 deletion lib/LibreCat/Cmd/queue.pm
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ LibreCat::Cmd::queue - show job queue status
librecat queue status
# Submit a YAML file job to the WORKER
librecat [--background] queue add_job WORKER FILE
librecat queue [--background] add_job WORKER FILE
# Start all configured workers
librecat queue start
Expand Down
47 changes: 47 additions & 0 deletions t/LibreCat/Cmd/audit.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ my $pkg;
BEGIN {
$pkg = 'LibreCat::Cmd::audit';
use_ok $pkg;

# add some test data
my $data = [
{
id => 1,
process => 'batch',
action => 'update',
message => 'test1',
time => '2018-01-01T12:00:00Z'
},
{
id => 2,
process => 'web',
action => 'update',
time => '2018-01-01T12:00:02Z'
},
{id => 3, time => '2018-01-01T12:00:04Z'},
{
id => 1,
process => 'batch',
action => 'update',
message => 'change ID 1 again',
time => '2018-01-01T12:00:06Z'
},
];
Catmandu->store('main')->bag('audit')->add_many($data);
}

require_ok $pkg;
Expand All @@ -23,6 +49,14 @@ require_ok $pkg;
ok $result->error, 'ok threw an exception: invalid nonsense';
}

{
my $result = test_app(qq|LibreCat::CLI| => ['help', 'audit']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/Usage:/, "Help message";
}

{
my $result = test_app(qq|LibreCat::CLI| => ['audit', 'list']);

Expand All @@ -31,6 +65,19 @@ require_ok $pkg;
my $output = $result->stdout;

ok $output , 'got an output';

like $output, qr/count: 4/, 'list count';

$result = test_app(qq|LibreCat::CLI| => ['audit', 'list', '1']);

ok !$result->error, 'ok threw no exception';

like $result->output, qr/count: 2/, 'list count';
}

END {
# cleanup test data
Catmandu->store('main')->bag('audit')->delete_all;
}

done_testing;
10 changes: 10 additions & 0 deletions t/LibreCat/Cmd/config.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use Catmandu::Sane;
use LibreCat -load => {layer_paths => [qw(t/layer)]};
use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use warnings FATAL => 'all';

my $pkg;
Expand All @@ -13,4 +15,12 @@ BEGIN {

require_ok $pkg;

{
my $result = test_app(qq|LibreCat::CLI| => ['help', 'copy']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/Usage:/, "Help message";
}

done_testing;
10 changes: 10 additions & 0 deletions t/LibreCat/Cmd/convert.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use Catmandu::Sane;
use LibreCat -load => {layer_paths => [qw(t/layer)]};
use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use warnings FATAL => 'all';

my $pkg;
Expand All @@ -13,4 +15,12 @@ BEGIN {

require_ok $pkg;

{
my $result = test_app(qq|LibreCat::CLI| => ['help', 'copy']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/Usage:/, "Help message";
}

done_testing;
8 changes: 8 additions & 0 deletions t/LibreCat/Cmd/copy.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use Catmandu::Sane;
use LibreCat -load => {layer_paths => [qw(t/layer)]};
use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use warnings FATAL => 'all';

my $pkg;
Expand All @@ -13,4 +15,10 @@ BEGIN {

require_ok $pkg;

my $result = test_app(qq|LibreCat::CLI| => ['help', 'copy']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/WARNING - Low level command/, "Help message";

done_testing;
8 changes: 8 additions & 0 deletions t/LibreCat/Cmd/count.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use Catmandu::Sane;
use LibreCat -load => {layer_paths => [qw(t/layer)]};
use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use warnings FATAL => 'all';

my $pkg;
Expand All @@ -13,4 +15,10 @@ BEGIN {

require_ok $pkg;

my $result = test_app(qq|LibreCat::CLI| => ['help', 'count']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/WARNING - Low level command/, "Help message";

done_testing;
8 changes: 8 additions & 0 deletions t/LibreCat/Cmd/delete.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use Catmandu::Sane;
use LibreCat -load => {layer_paths => [qw(t/layer)]};
use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use warnings FATAL => 'all';

my $pkg;
Expand All @@ -13,4 +15,10 @@ BEGIN {

require_ok $pkg;

my $result = test_app(qq|LibreCat::CLI| => ['help', 'delete']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/WARNING - Low level command/, "Help message";

done_testing;
78 changes: 76 additions & 2 deletions t/LibreCat/Cmd/department.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use Cpanel::JSON::XS;

my $pkg;

Expand All @@ -28,7 +27,22 @@ subtest 'initial cmd' => sub {
ok $result->error, 'missing command: threw an exception';
};

subtest 'list' => sub {
subtest 'invalid cmd' => sub {
my $result = test_app(qq|LibreCat::CLI| => ['department', 'do_nonsense']);
ok $result->error, 'missing command: threw an exception';
like $result->error, qr/should be one of/,
"error message for invalid command";
};

subtest 'help' => sub {
my $result = test_app(qq|LibreCat::CLI| => ['help', 'department']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/Usage:/, "Help message";
};

subtest 'list empty' => sub {
my $result = test_app(qq|LibreCat::CLI| => ['department', 'list']);

ok !$result->error, 'list: threw no exception';
Expand Down Expand Up @@ -98,6 +112,44 @@ subtest 'get' => sub {
is $record->{name}, 'Test faculty', 'got a valid department';
};

subtest 'get via id_file' => sub {
my $result = test_app(qq|LibreCat::CLI| =>
['department', 'get', 't/records/department_ids.txt']);

ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;

ok $output , 'got an output';

my $importer = Catmandu->importer('YAML', file => \$output);

my $record = $importer->first;

is $record->{_id}, 999000999, 'got really a 999000999 record';
is $record->{name}, 'Test faculty', 'got a valid department';
};

subtest 'list with options' => sub {
my $result = test_app(qq|LibreCat::CLI| => ['department', 'list']);

ok !$result->error, 'list: threw no exception';

my $output = $result->stdout;
ok $output , 'list departments: got an output';

my $count = count_department($output);

ok $count > 0, 'got some departments';

$result = test_app(
qq|LibreCat::CLI| => ['department', 'list', 'name=relativity']);

ok !$result->error, 'list: threw no exception';
$output = $result->stdout;
count_department($output) == 1, "got one department";
};

subtest 'tree' => sub {
my $result = test_app(qq|LibreCat::CLI| => ['department', 'tree']);

Expand All @@ -110,6 +162,13 @@ subtest 'export' => sub {

ok !$result->error, "threw no exception";
like $result->output, qr/_id:/, "export output";

$result = test_app(
qq|LibreCat::CLI| => ['department', 'export', 'name=relativity']);

ok !$result->error, "threw no exception";

count_department($result->output) == 1, "got one department";
};

subtest 'delete' => sub {
Expand All @@ -130,6 +189,21 @@ subtest 'delete' => sub {

$output = $result->stdout;
ok length($output) == 0, 'got no result';

$result = test_app(qq|LibreCat::CLI| =>
['department', 'delete', 'does-not-exist-123434']);

ok $result->error, 'throw exception: delete invalid id';
like $result->output, qr/ERROR: delete/, 'error message delete failed';
};

subtest 'tree with file' => sub {
my $result = test_app(qq|LibreCat::CLI| =>
['department', 'tree', 't/records/department-tree.yml']);

ok !$result->error, "threw no exception";
ok $result->output;
like $result->output, qr/added \d+/, "add tree via file";
};

done_testing;
Expand Down
8 changes: 8 additions & 0 deletions t/LibreCat/Cmd/drop.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use Catmandu::Sane;
use LibreCat -load => {layer_paths => [qw(t/layer)]};
use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use warnings FATAL => 'all';

my $pkg;
Expand All @@ -13,4 +15,10 @@ BEGIN {

require_ok $pkg;

my $result = test_app(qq|LibreCat::CLI| => ['help', 'drop']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/WARNING - Low level command/, "Help message";

done_testing;
8 changes: 8 additions & 0 deletions t/LibreCat/Cmd/export.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use Catmandu::Sane;
use LibreCat -load => {layer_paths => [qw(t/layer)]};
use LibreCat::CLI;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;
use warnings FATAL => 'all';

my $pkg;
Expand All @@ -13,4 +15,10 @@ BEGIN {

require_ok $pkg;

my $result = test_app(qq|LibreCat::CLI| => ['help', 'export']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/WARNING - Low level command/, "Help message";

done_testing;
28 changes: 27 additions & 1 deletion t/LibreCat/Cmd/file_store.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ require_ok $pkg;
ok $result->error, 'ok threw an exception';
}

{
my $result = test_app(qq|LibreCat::CLI| => ['help', 'file_store']);
ok !$result->error, 'ok threw no exception';

my $output = $result->stdout;
like $output, qr/Usage:/, "Help message";
}

{
my $result = test_app(qq|LibreCat::CLI| => ['file_store', 'do_nonsense']);
ok $result->error, 'invalid command threw an exception';

like $result->error, qr/should be one of/, "error message of invalid command";
}

{
my $result = test_app(qq|LibreCat::CLI| => ['file_store', 'list']);

Expand Down Expand Up @@ -64,7 +79,18 @@ require_ok $pkg;
my $output = $result->stdout;
ok $output , 'got an output';

like $output , qr/^key: 1234/, 'added 1234';
like $output , qr/^key: 1234/, 'get 1234';
}

{
my $result = test_app(qq|LibreCat::CLI| => ['file_store', 'exists', '1234']);

ok !$result->error, 'exists threw no exception';

my $output = $result->stdout;
ok $output , 'got an output';

like $output , qr/\d+ EXISTS/, 'exists 1234';
}

{
Expand Down

0 comments on commit c37d176

Please sign in to comment.