diff --git a/lib/Test/TA.pm b/lib/Test/TA.pm new file mode 100644 index 0000000000000000000000000000000000000000..20f64d537ff021360cd0078920969cada25f5a23 --- /dev/null +++ b/lib/Test/TA.pm @@ -0,0 +1,64 @@ +package Test::TA; +use Path::Tiny; +use Test::Cmd; +use Net::Ping; + +sub testhost { + return "sdvlzaamtestfotothek01.slub-dresden.de"; +} + +sub testport { + return 9200; +} + +sub is_testhost_available { + my $ping = Net::Ping->new('tcp'); + $ping->port_number( testport() ); + my $is_avail; + local $SIG{__WARN__} = sub {1;}; + $is_avail = $ping->ping(testhost()); + $ping->close(); + return $is_avail; +} + +{ + my $config_dir; + my $config_file; + my $cache_dir; + my $cache_file; + sub testapp { + # contains common code for tests under t/ + my $perl = $^X; + my $testapp = Test::Cmd->new( + prog => path(__FILE__)->parent->parent->parent->child('bin')->child('ta-tool.pl'), + workdir => '', + subdir => 'bin', + #verbose => 1, + interpreter => "$perl -I lib/ ", + ); + $config_dir = path($testapp->workpath())->child('.config'); + $config_dir->mkpath(); + $config_file = $config_dir->child('ta-tool.rc'); + $cache_dir = path($testapp->workpath())->child('.cache'); + $cache_dir->mkpath(); + $cache_file = $cache_dir->child('ta-tool.cache'); + my $testhost = testhost(); + my $testport = testport(); + $config_file->spew_utf8(<<_CFG_); +--- +elasticsearch_host: $testhost +elasticsearch_port: $testport +http_only: 1 +logdir: /tmp +password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345 +user: lza +_CFG_ + return $testapp; + } + + sub testconfigfile { + return $config_file; + } +} + +1; diff --git a/t/02-init.t b/t/02-init.t index a5b0a08183577f00869981d9d1a30c1325445df3..a459186ab7b3d7d5d512082966643db9aad57356 100644 --- a/t/02-init.t +++ b/t/02-init.t @@ -1,24 +1,20 @@ use v5.36; use Test::Cmd; use Test::More tests =>6; +use Test::TA; use Path::Tiny; -my $perl = $^X; -my $testapp = Test::Cmd->new( - prog => path(__FILE__)->parent->parent->child('bin')->child('ta-tool.pl'), - workdir => '', - subdir => 'bin', - #verbose => 1, - interpreter => "$perl -I lib/ ", -); -local $ENV{'HOME'} = $testapp->workpath(); $ENV{'TEST_ACTIVE'}=1; delete $ENV{PERL_MM_USE_DEFAULT}; +my $testapp = Test::TA::testapp(); +local $ENV{'HOME'} = $testapp->workpath(); my $config_dir = path($testapp->workpath())->child('.config'); $config_dir->mkpath(); my $config_file = $config_dir->child('ta-tool.rc'); +my $testhost = Test::TA::testhost(); my $cache_dir = path($testapp->workpath())->child('.cache'); $cache_dir->mkpath(); my $cache_file = $cache_dir->child('ta-tool.cache'); + # tests use_ok("SLUB::LZA::TA::Crypt"); is(SLUB::LZA::TA::Crypt::encrypt("199fc76b9d086d8937976634e93413bcd005d941"), "839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345", "ta-tool, init, check encryption"); @@ -45,7 +41,7 @@ lza 199fc76b9d086d8937976634e93413bcd005d941 199fc76b9d086d8937976634e93413bcd005d941 _EOF_ - args => 'init -D -v -e sdvlzaamtestfotothek01.slub-dresden.de', + args => 'init -D -v -e ' . $testhost, #args => 'init -e sdvlzaamtestfotothek01.slub-dresden.de -l /tmp', ); #say "STDOUT:",$testapp->stdout; @@ -57,7 +53,7 @@ _EOF_ my $config = $config_file->slurp_utf8(); is($config, <<_EXP_, "ta-tool init, config file as expected"); --- -elasticsearch_host: sdvlzaamtestfotothek01.slub-dresden.de +elasticsearch_host: $testhost elasticsearch_port: 9200 http_only: ~ password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345 diff --git a/t/03-count.t b/t/03-count.t index 99344967b1f2569989fec02f613b24283fe1b6a7..cfce5ab3437966e964644d5a0ac6423f3be6c414 100644 --- a/t/03-count.t +++ b/t/03-count.t @@ -1,33 +1,11 @@ use v5.36; use Test::Cmd; use Test::More tests =>6; -use Path::Tiny; -my $perl = $^X; -my $testapp = Test::Cmd->new( - prog => path(__FILE__)->parent->parent->child('bin')->child('ta-tool.pl'), - workdir => '', - subdir => 'bin', - #verbose => 1, - interpreter => "$perl -I lib/ ", -); +use Test::TA; +my $testapp = Test::TA::testapp(); +my $host = Test::TA::testhost(); local $ENV{'HOME'} = $testapp->workpath(); -my $config_dir = path($testapp->workpath())->child('.config'); -$config_dir->mkpath(); -my $config_file = $config_dir->child('ta-tool.rc'); -my $cache_dir = path($testapp->workpath())->child('.cache'); -$cache_dir->mkpath(); -my $cache_file = $cache_dir->child('ta-tool.cache'); -$config_file->spew_utf8(<<_CFG_); ---- -elasticsearch_host: sdvlzaamtestfotothek01.slub-dresden.de -elasticsearch_port: 9200 -http_only: 1 -logdir: /tmp -password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345 -user: lza -_CFG_ # tests - subtest 'help check' => sub { plan tests => 9; foreach my $param ("help count", "count -h", "count --help") { @@ -42,66 +20,81 @@ subtest 'help check' => sub { subtest 'check cli params' => sub { plan tests => 3; - $testapp->run(args => 'count --lzaid SLUB:LZA:goobi:1 --debug'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr//, 'ta-tool count by lzaid, wrong format, stdout'); - like($testapp->stderr, qr/Error: --[a-z].* expects.*Usage/s, 'ta-tool count by lzaid, wrong format, stderr'); - isnt($? >> 8, 0, 'ta-tool count by lzaid, wrong format, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'count --lzaid SLUB:LZA:goobi:1 --debug'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr//, 'ta-tool count by lzaid, wrong format, stdout'); + like($testapp->stderr, qr/Error: --[a-z].* expects.*Usage/s, 'ta-tool count by lzaid, wrong format, stderr'); + isnt($? >> 8, 0, 'ta-tool count by lzaid, wrong format, exit status'); + }; }; subtest 'elastic count existing lza id' => sub { plan tests => 6; - $testapp->run(args => 'count --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --debug'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^1$/s, 'ta-tool count by lzaid, existing, stdout'); - like($testapp->stderr, qr/\A\@must=.*/, 'ta-tool count by lzaid, existing, stderr'); - is($? >> 8, 0, 'ta-tool count by lzaid, no match, exit status'); - $testapp->run(args => 'count --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^1$/s, 'ta-tool count by lzaid, existing, stdout'); - like($testapp->stderr, qr/^$/, 'ta-tool count by lzaid, existing, stderr'); - is($? >> 8, 0, 'ta-tool count by lzaid, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 6 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'count --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --debug'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^1$/s, 'ta-tool count by lzaid, existing, stdout'); + like($testapp->stderr, qr/\A\@must=.*/, 'ta-tool count by lzaid, existing, stderr'); + is($? >> 8, 0, 'ta-tool count by lzaid, no match, exit status'); + $testapp->run(args => 'count --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^1$/s, 'ta-tool count by lzaid, existing, stdout'); + like($testapp->stderr, qr/^$/, 'ta-tool count by lzaid, existing, stderr'); + is($? >> 8, 0, 'ta-tool count by lzaid, existing, exit status'); + }; }; subtest 'elastic count existing dc entry' => sub { plan tests => 3; - $testapp->run(args => 'count --descriptive "Retrodigitalisierte Fotosn"'); #SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^30$/, 'ta-tool count by dc, existing, stdout'); - like($testapp->stderr, qr/^$/, 'ta-tool count by dc, existing, stderr'); - is($? >> 8, 0, 'ta-tool count by lzaid, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'count --descriptive "Retrodigitalisierte Fotosn"'); #SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^30$/, 'ta-tool count by dc, existing, stdout'); + like($testapp->stderr, qr/^$/, 'ta-tool count by dc, existing, stderr'); + is($? >> 8, 0, 'ta-tool count by lzaid, existing, exit status'); + }; }; subtest 'elastic count dates' => sub { plan tests => 6; - $testapp->run(args => 'count --creationdate 2023-09-05'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^2$/, 'ta-tool count date, existing, stdout'); - like($testapp->stderr, qr/^$/, 'ta-tool count date, existing, stderr'); - is($? >> 8, 0, 'ta-tool count date, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 6 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'count --creationdate 2023-09-05'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^2$/, 'ta-tool count date, existing, stdout'); + like($testapp->stderr, qr/^$/, 'ta-tool count date, existing, stderr'); + is($? >> 8, 0, 'ta-tool count date, existing, exit status'); - $testapp->run(args => 'count --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^25$/, 'ta-tool count dates, existing, stdout'); - like($testapp->stderr, qr/^$/, 'ta-tool count dates, existing, stderr'); - is($? >> 8, 0, 'ta-tool count dates, existing, exit status'); + $testapp->run(args => 'count --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^25$/, 'ta-tool count dates, existing, stdout'); + like($testapp->stderr, qr/^$/, 'ta-tool count dates, existing, stderr'); + is($? >> 8, 0, 'ta-tool count dates, existing, exit status'); + }; }; subtest 'overrides' => sub { plan tests => 3; - $testapp->run(args => 'count --elasticsearch-host localhost --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^$/, 'ta-tool count dates, existing, override, stdout'); - like($testapp->stderr, qr/^Hint: override local config with/, 'ta-tool count dates, existing, override, stderr'); - is($? >> 8, 111, 'ta-tool count dates, existing, override, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'count --elasticsearch-host localhost --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^$/, 'ta-tool count dates, existing, override, stdout'); + like($testapp->stderr, qr/^Hint: override local config with/, 'ta-tool count dates, existing, override, stderr'); + is($? >> 8, 111, 'ta-tool count dates, existing, override, exit status'); + }; }; 1; diff --git a/t/03-info.t b/t/03-info.t index 544495c45bf5e01574ee3c55771e6e4a31e513f4..74dc73f720ab87c807d259eaf7c1b92e17e416ae 100644 --- a/t/03-info.t +++ b/t/03-info.t @@ -1,31 +1,10 @@ use v5.36; use Test::Cmd; use Test::More tests =>3; -use Path::Tiny; -my $perl = $^X; -my $testapp = Test::Cmd->new( - prog => path(__FILE__)->parent->parent->child('bin')->child('ta-tool.pl'), - workdir => '', - subdir => 'bin', - #verbose => 1, - interpreter => "$perl -I lib/ ", -); +use Test::TA; +my $testapp = Test::TA::testapp(); +my $host = Test::TA::testhost(); local $ENV{'HOME'} = $testapp->workpath(); -my $config_dir = path($testapp->workpath())->child('.config'); -$config_dir->mkpath(); -my $config_file = $config_dir->child('ta-tool.rc'); -my $cache_dir = path($testapp->workpath())->child('.cache'); -$cache_dir->mkpath(); -my $cache_file = $cache_dir->child('ta-tool.cache'); -$config_file->spew_utf8(<<_CFG_); ---- -elasticsearch_host: sdvlzaamtestfotothek01.slub-dresden.de -elasticsearch_port: 9200 -http_only: 1 -logdir: /tmp -password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345 -user: lza -_CFG_ # tests subtest 'help check' => sub { plan tests => 9; @@ -41,21 +20,26 @@ subtest 'help check' => sub { subtest 'elastic search version' => sub { plan tests => 3; - - $testapp->run(args => 'info --target-version'); - like($testapp->stdout, qr/^6\.\d\.\d{1,2}$/, 'ta-tool elasticsearch version, stdout'); - like($testapp->stderr, qr/^$/, 'ta-tool elasticsearch version, stderr'); - is($? >> 8, 0, 'ta-tool elasticsearch version, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'info --target-version'); + like($testapp->stdout, qr/^6\.\d\.\d{1,2}$/, 'ta-tool elasticsearch version, stdout'); + like($testapp->stderr, qr/^$/, 'ta-tool elasticsearch version, stderr'); + is($? >> 8, 0, 'ta-tool elasticsearch version, exit status'); + }; }; subtest 'overrides' => sub { plan tests => 3; - $testapp->run(args => 'info --elasticsearch-host localhost --target-version'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^$/, 'ta-tool elasticsearch version, override, stdout'); - like($testapp->stderr, qr/^Hint: override local config/, 'ta-tool elasticsearch version, override, stderr'); - is($? >> 8, 111, 'ta-tool elasticsearch version, override, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'info --elasticsearch-host localhost --target-version'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^$/, 'ta-tool elasticsearch version, override, stdout'); + like($testapp->stderr, qr/^Hint: override local config/, 'ta-tool elasticsearch version, override, stderr'); + is($? >> 8, 111, 'ta-tool elasticsearch version, override, exit status'); + }; }; 1; diff --git a/t/03-report.t b/t/03-report.t index ea0086b4db778a6c70f18a13b80cec61128f5be2..ebc1187c75e841273ab3fbc495cb26357f3b1724 100644 --- a/t/03-report.t +++ b/t/03-report.t @@ -2,30 +2,10 @@ use v5.36; use Test::Cmd; use Test::More tests => 3; use Path::Tiny; -my $perl = $^X; -my $testapp = Test::Cmd->new( - prog => path(__FILE__)->parent->parent->child('bin')->child('ta-tool.pl'), - workdir => '', - subdir => 'bin', - #verbose => 1, - interpreter => "$perl -I lib/ ", -); +use Test::TA; +my $testapp = Test::TA::testapp(); +my $host = Test::TA::testhost(); local $ENV{'HOME'} = $testapp->workpath(); -my $config_dir = path($testapp->workpath())->child('.config'); -$config_dir->mkpath(); -my $config_file = $config_dir->child('ta-tool.rc'); -my $cache_dir = path($testapp->workpath())->child('.cache'); -$cache_dir->mkpath(); -my $cache_file = $cache_dir->child('ta-tool.cache'); -$config_file->spew_utf8(<<_CFG_); ---- -elasticsearch_host: sdvlzaamtestfotothek01.slub-dresden.de -elasticsearch_port: 9200 -http_only: 1 -logdir: /tmp -password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345 -user: lza -_CFG_ # tests subtest 'help check' => sub { plan tests => 9; @@ -41,50 +21,56 @@ subtest 'help check' => sub { subtest 'check cli params' => sub { plan tests => 15; - $testapp->run(args => 'report'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^:lang: en\n:doctype: article\n:date:.*\n:generator:.*\n:toc:\n\n= Report from.*\n\n== Complete archive\n\n=== count/s, 'ta-tool report, base, stdout'); - like($testapp->stderr, qr/^reporting for period/s, 'ta-tool report, base, stderr'); - is($? >> 8, 0, 'ta-tool report, base, exit status'); + SKIP: { + skip "testhost '$host' not available", 15 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'report'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^:lang: en\n:doctype: article\n:date:.*\n:generator:.*\n:toc:\n\n= Report from.*\n\n== Complete archive\n\n=== count/s, 'ta-tool report, base, stdout'); + like($testapp->stderr, qr/^reporting for period/s, 'ta-tool report, base, stderr'); + is($? >> 8, 0, 'ta-tool report, base, exit status'); - $testapp->run(args => 'report --output-as-csv'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n"([a-z]+)",,"\d{4}-\d{2}-\d{2}","\d{4}-\d{2}-\d{2}","([a-z ]+)",,"([a-z ]+)",\d+(\.\d+)?\n/s, 'ta-tool report, base as CSV, stdout'); - like($testapp->stderr, qr/^reporting for period/s, 'ta-tool report, base as CSV, stderr'); - is($? >> 8, 0, 'ta-tool report, base as CSV, exit status'); + $testapp->run(args => 'report --output-as-csv'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n"([a-z]+)",,"\d{4}-\d{2}-\d{2}","\d{4}-\d{2}-\d{2}","([a-z ]+)",,"([a-z ]+)",\d+(\.\d+)?\n/s, 'ta-tool report, base as CSV, stdout'); + like($testapp->stderr, qr/^reporting for period/s, 'ta-tool report, base as CSV, stderr'); + is($? >> 8, 0, 'ta-tool report, base as CSV, exit status'); - $testapp->run(args => 'report --output-as-csv --with-ldp'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*LDP/s, 'ta-tool report, with ldp, stdout'); - like($testapp->stderr, qr/^reporting for period.*HINT:.*with-ldp/s, 'ta-tool report, with ldp, stderr'); - is($? >> 8, 0, 'ta-tool report, with ldp, exit status'); + $testapp->run(args => 'report --output-as-csv --with-ldp'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*LDP/s, 'ta-tool report, with ldp, stdout'); + like($testapp->stderr, qr/^reporting for period.*HINT:.*with-ldp/s, 'ta-tool report, with ldp, stderr'); + is($? >> 8, 0, 'ta-tool report, with ldp, exit status'); - $testapp->run(args => 'report --output-as-csv --with-filetypes'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*total/s, 'ta-tool report, with filetype, stdout'); - like($testapp->stderr, qr/^reporting for period.*HINT:.*with-filetype/s, 'ta-tool report, with filetype, stderr'); - is($? >> 8, 0, 'ta-tool report, with filetype, exit status'); + $testapp->run(args => 'report --output-as-csv --with-filetypes'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*total/s, 'ta-tool report, with filetype, stdout'); + like($testapp->stderr, qr/^reporting for period.*HINT:.*with-filetype/s, 'ta-tool report, with filetype, stderr'); + is($? >> 8, 0, 'ta-tool report, with filetype, exit status'); - $testapp->run(args => 'report --output-as-csv --with-ldp --with-filetypes'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*LDP/s, 'ta-tool report, with ldp and filetypes, stdout'); - like($testapp->stderr, qr/^reporting for period.*HINT:.*with-ldp.*with-filetype/s, 'ta-tool report, with ldp and filetypes, stderr'); - is($? >> 8, 0, 'ta-tool report, with ldp and filetypes, exit status'); + $testapp->run(args => 'report --output-as-csv --with-ldp --with-filetypes'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^"set","subset","timespan_from","timespan_to","aip_state","filter","flavour","value"\n.*LDP/s, 'ta-tool report, with ldp and filetypes, stdout'); + like($testapp->stderr, qr/^reporting for period.*HINT:.*with-ldp.*with-filetype/s, 'ta-tool report, with ldp and filetypes, stderr'); + is($? >> 8, 0, 'ta-tool report, with ldp and filetypes, exit status'); + }; }; subtest 'overrides' => sub { plan tests => 3; - $testapp->run(args => 'report --elasticsearch-host localhost'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^$/s, 'ta-tool report, base, stdout'); - like($testapp->stderr, qr/^Hint: override local config with/s, 'ta-tool report, base, stderr'); - is($? >> 8, 111, 'ta-tool report, base, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'report --elasticsearch-host localhost'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^$/s, 'ta-tool report, base, stdout'); + like($testapp->stderr, qr/^Hint: override local config with/s, 'ta-tool report, base, stderr'); + is($? >> 8, 111, 'ta-tool report, base, exit status'); + }; }; 1; diff --git a/t/03-search.t b/t/03-search.t index e96c8de1a33c1756f86f19ae73087ef5c74c204f..8f89dbdf23d5cf6a5fb81dde9ac2e6f1a0e21716 100644 --- a/t/03-search.t +++ b/t/03-search.t @@ -1,31 +1,10 @@ use v5.36; use Test::Cmd; use Test::More tests =>11; -use Path::Tiny; -my $perl = $^X; -my $testapp = Test::Cmd->new( - prog => path(__FILE__)->parent->parent->child('bin')->child('ta-tool.pl'), - workdir => '', - subdir => 'bin', - #verbose => 1, - interpreter => "$perl -I lib/ ", -); +use Test::TA; +my $testapp = Test::TA::testapp(); +my $host = Test::TA::testhost(); local $ENV{'HOME'} = $testapp->workpath(); -my $config_dir = path($testapp->workpath())->child('.config'); -$config_dir->mkpath(); -my $config_file = $config_dir->child('ta-tool.rc'); -my $cache_dir = path($testapp->workpath())->child('.cache'); -$cache_dir->mkpath(); -my $cache_file = $cache_dir->child('ta-tool.cache'); -$config_file->spew_utf8(<<_CFG_); ---- -elasticsearch_host: sdvlzaamtestfotothek01.slub-dresden.de -elasticsearch_port: 9200 -http_only: 1 -logdir: /tmp -password: 839852bed005a7f1237578a6ac1197c142f7d0dd58bb248446dc7849d4bf770902e7f980ad83d39008ad638bc41e2345 -user: lza -_CFG_ # tests subtest 'help check' => sub { plan tests => 9; @@ -41,167 +20,197 @@ subtest 'help check' => sub { subtest 'check cli params' => sub { plan tests => 3; - $testapp->run(args => 'search --lzaid SLUB:LZA:goobi:1 --debug'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr//, 'ta-tool search by lzaid, wrong format, stdout'); - like($testapp->stderr, qr/^$.*Error: --[a-z].* expects.*Usage/s, 'ta-tool search by lzaid, wrong format, stderr'); - isnt($? >> 8, 0, 'ta-tool search by lzaid, wrong format, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --lzaid SLUB:LZA:goobi:1 --debug'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr//, 'ta-tool search by lzaid, wrong format, stdout'); + like($testapp->stderr, qr/^$.*Error: --[a-z].* expects.*Usage/s, 'ta-tool search by lzaid, wrong format, stderr'); + isnt($? >> 8, 0, 'ta-tool search by lzaid, wrong format, exit status'); + }; }; subtest 'elastic search non-existing lza id' => sub { plan tests => 6; - $testapp->run(args => 'search --lzaid SLUB:LZA:Goobi:goobi:1 --debug'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A\s*\Z/s, 'ta-tool search by lzaid, no match, stdout'); - like($testapp->stderr, qr/\A\@must.*\@should.*query:.*found 0 results\Z/s, 'ta-tool search by lzaid, no match, stderr'); - is($? >> 8, 0, 'ta-tool search by lzaid, no match, exit status'); - - $testapp->run(args => 'search --lzaid SLUB:LZA:Goobi:goobi:1'); - like($testapp->stdout, qr/\A\s*\Z/s, 'ta-tool search by lzaid, no match, stdout'); - like($testapp->stderr, qr/^found 0 results$/, 'ta-tool search by lzaid, no match, stderr'); - is($? >> 8, 0, 'ta-tool search by lzaid, no match, exit status'); + SKIP: { + skip "testhost '$host' not available", 6 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --lzaid SLUB:LZA:Goobi:goobi:1 --debug'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A\s*\Z/s, 'ta-tool search by lzaid, no match, stdout'); + like($testapp->stderr, qr/\A\@must.*\@should.*query:.*found 0 results\Z/s, 'ta-tool search by lzaid, no match, stderr'); + is($? >> 8, 0, 'ta-tool search by lzaid, no match, exit status'); + + $testapp->run(args => 'search --lzaid SLUB:LZA:Goobi:goobi:1'); + like($testapp->stdout, qr/\A\s*\Z/s, 'ta-tool search by lzaid, no match, stdout'); + like($testapp->stderr, qr/^found 0 results$/, 'ta-tool search by lzaid, no match, stderr'); + is($? >> 8, 0, 'ta-tool search by lzaid, no match, exit status'); + }; }; subtest 'elastic search existing lza id' => sub { plan tests => 6; - $testapp->run(args => 'search --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --debug'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\Z/s, 'ta-tool search by lzaid, existing, stdout'); - like($testapp->stderr, qr/\A\@must.*\@should.*query:.*found 1 result\nreporting results output as csv\Z/s, 'ta-tool search by lzaid, existing, stderr'); - is($? >> 8, 0, 'ta-tool search by lzaid, no match, exit status'); - - $testapp->run(args => 'search --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\Z/s, 'ta-tool search by lzaid, existing, stdout'); - like($testapp->stderr, qr/\Afound 1 result\nreporting results output as csv\Z/s, 'ta-tool search by lzaid, existing, stderr'); - is($? >> 8, 0, 'ta-tool search by lzaid, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 6 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --debug'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\Z/s, 'ta-tool search by lzaid, existing, stdout'); + like($testapp->stderr, qr/\A\@must.*\@should.*query:.*found 1 result\nreporting results output as csv\Z/s, 'ta-tool search by lzaid, existing, stderr'); + is($? >> 8, 0, 'ta-tool search by lzaid, no match, exit status'); + + $testapp->run(args => 'search --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\Z/s, 'ta-tool search by lzaid, existing, stdout'); + like($testapp->stderr, qr/\Afound 1 result\nreporting results output as csv\Z/s, 'ta-tool search by lzaid, existing, stderr'); + is($? >> 8, 0, 'ta-tool search by lzaid, existing, exit status'); + }; }; subtest 'elastic search existing dc entry' => sub { plan tests => 3; - $testapp->run(args => 'search --descriptive "Retrodigitalisierte Fotosn"'); #SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid"\n"6ae5f1f0-5306-404f-8fb7-445f82416932"\n"9a254f9d-1c19-478a-aacb-43be3a3c7d9d"\n.*"4f7516e4-23c8-4750-a411-91359fb7a869"\Z/s, 'ta-tool search by dc, existing, stdout'); - like($testapp->stderr, qr/\Afound 30 results\nreporting results 1 … 10 output as csv\Z/s, 'ta-tool search by dc, existing, stderr'); - is($? >> 8, 0, 'ta-tool search by lzaid, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --descriptive "Retrodigitalisierte Fotosn"'); #SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid"\n"6ae5f1f0-5306-404f-8fb7-445f82416932"\n"9a254f9d-1c19-478a-aacb-43be3a3c7d9d"\n.*"4f7516e4-23c8-4750-a411-91359fb7a869"\Z/s, 'ta-tool search by dc, existing, stdout'); + like($testapp->stderr, qr/\Afound 30 results\nreporting results 1 … 10 output as csv\Z/s, 'ta-tool search by dc, existing, stderr'); + is($? >> 8, 0, 'ta-tool search by lzaid, existing, exit status'); + }; }; subtest 'check output formats' => sub { plan tests => 9; - $testapp->run(args => 'search --output-as-raw --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 '); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A\{\n\s*hits\s*\{\n\s*hits\s*\[\n/s, 'ta-tool search, raw output, stdout'); - like($testapp->stderr, qr/\Afound 1 result\nreporting results output as raw\Z/s, 'ta-tool search, raw output, stderr'); - is($? >> 8, 0, 'ta-tool search, raw output, exit status'); - - $testapp->run(args => 'search --output-as-csv --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --with-lzaid'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid","slubarchiv_lzaid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2","SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111"\Z/s, 'ta-tool search, CSV output, stdout'); - like($testapp->stderr, qr/\Afound 1 result\nreporting results output as csv\Z/s, 'ta-tool search, CSV output, stderr'); - is($? >> 8, 0, 'ta-tool search, CSV output, exit status'); - - $testapp->run(args => 'search --output-as-rsv --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --with-lzaid'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\Aaipid\x{ff}slubarchiv_lzaid\x{ff}\x{fd}47daf26a-02a1-4776-a8db-de04c6708bd2\x{ff}SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111\x{ff}\x{fd}\Z/s, 'ta-tool search, RSV output, stdout'); - like($testapp->stderr, qr/\Afound 1 result\nreporting results output as rsv\Z/s, 'ta-tool search, RSV output, stderr'); - is($? >> 8, 0, 'ta-tool search, RSV output, exit status'); + SKIP: { + skip "testhost '$host' not available", 9 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --output-as-raw --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 '); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A\{\n\s*hits\s*\{\n\s*hits\s*\[\n/s, 'ta-tool search, raw output, stdout'); + like($testapp->stderr, qr/\Afound 1 result\nreporting results output as raw\Z/s, 'ta-tool search, raw output, stderr'); + is($? >> 8, 0, 'ta-tool search, raw output, exit status'); + + $testapp->run(args => 'search --output-as-csv --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --with-lzaid'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid","slubarchiv_lzaid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2","SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111"\Z/s, 'ta-tool search, CSV output, stdout'); + like($testapp->stderr, qr/\Afound 1 result\nreporting results output as csv\Z/s, 'ta-tool search, CSV output, stderr'); + is($? >> 8, 0, 'ta-tool search, CSV output, exit status'); + + $testapp->run(args => 'search --output-as-rsv --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 --with-lzaid'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\Aaipid\x{ff}slubarchiv_lzaid\x{ff}\x{fd}47daf26a-02a1-4776-a8db-de04c6708bd2\x{ff}SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111\x{ff}\x{fd}\Z/s, 'ta-tool search, RSV output, stdout'); + like($testapp->stderr, qr/\Afound 1 result\nreporting results output as rsv\Z/s, 'ta-tool search, RSV output, stderr'); + is($? >> 8, 0, 'ta-tool search, RSV output, exit status'); + }; }; subtest 'check with-options' => sub { plan tests => 57; - foreach my $with (qw( - External-Description - External-Identifier - LDP-collection - LDP-funder - LDP-lender - LDP-project - SLUBArchiv-archivalValueDescription - SLUBArchiv-exportToArchiveDate - SLUBArchiv-externalId - SLUBArchiv-externalIsilId - SLUBArchiv-externalWorkflow - SLUBArchiv-hasConservationReason - SLUBArchiv-lzaId - SLUBArchiv-migrated-AIP - SLUBArchiv-origin-AIS - SLUBArchiv-previous-AIP - SLUBArchiv-rightsVersion - SLUBArchiv-sipVersion - Title - )) { - my $with_opt = "--with-" . lc($with); - my $head = lc($with); - $head =~ s/-/_/g; - $testapp->run(args => 'search --output-as-csv --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 ' . $with_opt); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid","$head"\n"47daf26a-02a1-4776-a8db-de04c6708bd2",("[A-Za-zäöüßÄÖÜ0-9_:. -]*")|\d+(\.\d+)?\Z/s, 'ta-tool search, check "' . $with_opt . '", stdout'); - like($testapp->stderr, qr/\Afound 1 result\nreporting results output as csv\Z/s, 'ta-tool search, check "' . $with_opt . '", stderr'); - is($? >> 8, 0, 'ta-tool search, check "' . $with_opt . '", exit status'); - } + SKIP: { + skip "testhost '$host' not available", 57 unless Test::TA::is_testhost_available(); + foreach my $with (qw( + External-Description + External-Identifier + LDP-collection + LDP-funder + LDP-lender + LDP-project + SLUBArchiv-archivalValueDescription + SLUBArchiv-exportToArchiveDate + SLUBArchiv-externalId + SLUBArchiv-externalIsilId + SLUBArchiv-externalWorkflow + SLUBArchiv-hasConservationReason + SLUBArchiv-lzaId + SLUBArchiv-migrated-AIP + SLUBArchiv-origin-AIS + SLUBArchiv-previous-AIP + SLUBArchiv-rightsVersion + SLUBArchiv-sipVersion + Title + )) { + my $with_opt = "--with-" . lc($with); + my $head = lc($with); + $head =~ s/-/_/g; + $testapp->run(args => 'search --output-as-csv --lzaid SLUB:LZA:testworkflow:testcases:test-sip_2023-01-01-11_11-11_11111 ' . $with_opt); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid","$head"\n"47daf26a-02a1-4776-a8db-de04c6708bd2",("[A-Za-zäöüßÄÖÜ0-9_:. -]*")|\d+(\.\d+)?\Z/s, 'ta-tool search, check "' . $with_opt . '", stdout'); + like($testapp->stderr, qr/\Afound 1 result\nreporting results output as csv\Z/s, 'ta-tool search, check "' . $with_opt . '", stderr'); + is($? >> 8, 0, 'ta-tool search, check "' . $with_opt . '", exit status'); + } + }; }; subtest 'search by files' => sub { plan tests => 3; - $testapp->run(args => 'search --pronom-id fmt/101'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid"\n.*"47daf26a-02a1-4776-a8db-de04c6708bd2"/s, 'ta-tool search by pronom-id, existing, stdout'); - like($testapp->stderr, qr/\Afound 166 results\nreporting results 1 … 10 output as csv\Z/s, 'ta-tool search by pronom-id, existing, stderr'); - is($? >> 8, 0, 'ta-tool search by pronom-id, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --pronom-id fmt/101'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid"\n.*"47daf26a-02a1-4776-a8db-de04c6708bd2"/s, 'ta-tool search by pronom-id, existing, stdout'); + like($testapp->stderr, qr/\Afound 166 results\nreporting results 1 … 10 output as csv\Z/s, 'ta-tool search by pronom-id, existing, stderr'); + is($? >> 8, 0, 'ta-tool search by pronom-id, existing, exit status'); + }; }; subtest 'check paginations' => sub { plan tests => 6; - $testapp->run(args => 'search --pronom-id fmt/101 --with-result-index --output-as-csv --startrecord 2 --maxrecords 1'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"idx","aipid"\n2,"2ed0c682-4565-4320-8247-6da0cc0642f1"\Z/s, 'ta-tool search by pronom-id, existing, stdout'); - like($testapp->stderr, qr/\Afound 166 results\nreporting results output as csv\Z/s, 'ta-tool search by pronom-id, existing, stderr'); - is($? >> 8, 0, 'ta-tool search by pronom-id, existing, exit status'); - - $testapp->run(args => 'search --pronom-id fmt/101 --with-result-index --output-as-csv --startrecord 3 --maxrecords 2'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"idx","aipid"\n3,"5687a403-673d-45c1-864f-f7f22a7aadb9"\n4,"db256475-10bd-40ee-83cc-dab8424346ba"\Z/s, 'ta-tool search by pronom-id, existing, stdout'); - like($testapp->stderr, qr/\Afound 166 results\nreporting results 3 … 4 output as csv\Z/s, 'ta-tool search by pronom-id, existing, stderr'); - is($? >> 8, 0, 'ta-tool search by pronom-id, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 6 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --pronom-id fmt/101 --with-result-index --output-as-csv --startrecord 2 --maxrecords 1'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"idx","aipid"\n2,"2ed0c682-4565-4320-8247-6da0cc0642f1"\Z/s, 'ta-tool search by pronom-id, existing, stdout'); + like($testapp->stderr, qr/\Afound 166 results\nreporting results output as csv\Z/s, 'ta-tool search by pronom-id, existing, stderr'); + is($? >> 8, 0, 'ta-tool search by pronom-id, existing, exit status'); + + $testapp->run(args => 'search --pronom-id fmt/101 --with-result-index --output-as-csv --startrecord 3 --maxrecords 2'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"idx","aipid"\n3,"5687a403-673d-45c1-864f-f7f22a7aadb9"\n4,"db256475-10bd-40ee-83cc-dab8424346ba"\Z/s, 'ta-tool search by pronom-id, existing, stdout'); + like($testapp->stderr, qr/\Afound 166 results\nreporting results 3 … 4 output as csv\Z/s, 'ta-tool search by pronom-id, existing, stderr'); + is($? >> 8, 0, 'ta-tool search by pronom-id, existing, exit status'); + }; }; subtest 'search dates' => sub { plan tests => 6; - $testapp->run(args => 'search --creationdate 2023-09-05'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\n"e8bfdec5-d201-42d6-b293-94bb1668a7b6"\Z/s, 'ta-tool search date, existing, stdout'); - like($testapp->stderr, qr/\Afound 2 results\nreporting results 1 … 2 output as csv/s, 'ta-tool search date, existing, stderr'); - is($? >> 8, 0, 'ta-tool search date, existing, exit status'); - - $testapp->run(args => 'search --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\n/s, 'ta-tool search dates, existing, stdout'); - like($testapp->stderr, qr/\Afound 25 results\nreporting results 1 … 10 output as csv/s, 'ta-tool search dates, existing, stderr'); - is($? >> 8, 0, 'ta-tool search dates, existing, exit status'); + SKIP: { + skip "testhost '$host' not available", 6 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --creationdate 2023-09-05'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\n"e8bfdec5-d201-42d6-b293-94bb1668a7b6"\Z/s, 'ta-tool search date, existing, stdout'); + like($testapp->stderr, qr/\Afound 2 results\nreporting results 1 … 2 output as csv/s, 'ta-tool search date, existing, stderr'); + is($? >> 8, 0, 'ta-tool search date, existing, exit status'); + + $testapp->run(args => 'search --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/\A"aipid"\n"47daf26a-02a1-4776-a8db-de04c6708bd2"\n/s, 'ta-tool search dates, existing, stdout'); + like($testapp->stderr, qr/\Afound 25 results\nreporting results 1 … 10 output as csv/s, 'ta-tool search dates, existing, stderr'); + is($? >> 8, 0, 'ta-tool search dates, existing, exit status'); + }; }; subtest 'overrides' => sub { plan tests => 3; - $testapp->run(args => 'search --elasticsearch-host localhost --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); - #say "STDOUT:",$testapp->stdout; - #say "STDERR:",$testapp->stderr; - like($testapp->stdout, qr/^$/s, 'ta-tool search dates, existing, override, stdout'); - like($testapp->stderr, qr/^Hint: override local config with/s, 'ta-tool search dates, existing, override stderr'); - is($? >> 8, 111, 'ta-tool search dates, existing, override, exit status'); + SKIP: { + skip "testhost '$host' not available", 3 unless Test::TA::is_testhost_available(); + $testapp->run(args => 'search --elasticsearch-host localhost --creationdate-from 2023-09-05 --creationdate-to 2023-12-22'); + #say "STDOUT:",$testapp->stdout; + #say "STDERR:",$testapp->stderr; + like($testapp->stdout, qr/^$/s, 'ta-tool search dates, existing, override, stdout'); + like($testapp->stderr, qr/^Hint: override local config with/s, 'ta-tool search dates, existing, override stderr'); + is($? >> 8, 111, 'ta-tool search dates, existing, override, exit status'); + }; }; 1;