diff --git a/t/Catmandu-Cmd-stream.t b/t/Catmandu-Cmd-stream.t index 2983ec93c..6a5ff3d0d 100644 --- a/t/Catmandu-Cmd-stream.t +++ b/t/Catmandu-Cmd-stream.t @@ -6,6 +6,7 @@ use Test::More; use Test::Exception; use App::Cmd::Tester::CaptureExternal; use Cpanel::JSON::XS; +use Path::Tiny; use utf8; my $pkg; @@ -18,6 +19,8 @@ require_ok $pkg; use Catmandu::CLI; +path("t/tmp/cmd-stream")->mkpath; + note("download"); { my $result = test_app( @@ -35,7 +38,7 @@ note("upload"); { my $result = test_app( qq|Catmandu::CLI| => [ - qw(stream cpanfile to File::Simple --root t/data --keysize 9 --bag 456 --id test.txt) + qw(stream cpanfile to File::Simple --root t/tmp/cmd-stream --keysize 9 --bag 456 --id test.txt) ] ); @@ -43,9 +46,11 @@ note("upload"); is $result->error, undef, 'threw no exceptions'; - ok -f "t/data/000/000/456/test.txt", "found the correct file"; + ok -f "t/tmp/cmd-stream/000/000/456/test.txt", "found the correct file"; - unlink "t/data/000/000/456/test.txt"; + unlink "t/tmp/cmd-stream/000/000/456/test.txt"; } +path("t/tmp/cmd-stream")->remove_tree; + done_testing; diff --git a/t/Catmandu-Plugin-SideCar.t b/t/Catmandu-Plugin-SideCar.t index 2b21f4617..31020980a 100644 --- a/t/Catmandu-Plugin-SideCar.t +++ b/t/Catmandu-Plugin-SideCar.t @@ -5,6 +5,7 @@ use warnings; use Test::More; use Test::Exception; use Catmandu; +use Path::Tiny; use utf8; my $pkg; @@ -15,11 +16,13 @@ BEGIN { } require_ok $pkg; +path("t/tmp/sidecar")->mkpath; + note("Combined Simple + Hash sidecar"); { my $store = Catmandu->store( 'File::Simple', - root => 't/data3', + root => 't/tmp/sidecar', keysize => 9, bags => { index => @@ -33,33 +36,33 @@ note("Combined Simple + Hash sidecar"); ok $index , 'got an index'; note("...exists"); - ok !$index->exists('1234'); + ok !$index->exists('9012'); note("...add"); - ok $index->add({_id => 1234, foo => 'bar', test => [1, 2, 3]}), - 'adding bag `1234`'; + ok $index->add({_id => 9012, foo => 'bar', test => [1, 2, 3]}), + 'adding bag `9012`'; - ok -d "t/data3/000/001/234"; + ok -d "t/tmp/sidecar/000/009/012"; note("...get"); - my $item = $index->get('1234'); + my $item = $index->get('9012'); ok $item; - is_deeply $item , {_id => 1234, foo => 'bar', test => [1, 2, 3]}, + is_deeply $item , {_id => 9012, foo => 'bar', test => [1, 2, 3]}, 'found combined metadata and file data'; note("...bag"); - my $container = $store->bag('1234'); + my $container = $store->bag('9012'); - ok $container , 'got bag(1234)'; + ok $container , 'got bag(9012)'; note("...upload"); ok $container->upload(IO::File->new('t/data2/000/000/001/test.txt'), 'test1.txt'); - ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists (2)'; + ok -f 't/tmp/sidecar/000/009/012/test1.txt', 'test1.txt exists (2)'; note("...list"); my $array = [sort @{$container->map(sub {shift->{_id}})->to_array}]; @@ -91,8 +94,7 @@ note("Combined Simple + Hash sidecar"); is_deeply $array , [], 'got correct response'; - ok !-f 't/data/000/001/234/test1.txt', 'test1.txt doesnt exists (1)'; - ok !-f 't/data3/000/001/234/test1.txt', 'test1.txt doesnt exists (2)'; + ok !-f 't/tmp/sidecar/000/009/012/test1.txt', 'test1.txt doesnt exists (2)'; note("...delete_all (index)"); lives_ok {$index->delete_all()} 'delete_all'; @@ -111,7 +113,7 @@ note("Combined Hash + Simple sidecar"); plugins => [qw(SideCar)], sidecar => { package => "File::Simple", - options => {'root' => 't/data3', 'keysize' => 9,} + options => {'root' => 't/tmp/sidecar', 'keysize' => 9,} }, sidecar_bag => 'index' } @@ -120,22 +122,22 @@ note("Combined Hash + Simple sidecar"); ok $store , 'got a store'; - ok $store->bag->add({_id => '1234', name => 'patrick'}), + ok $store->bag->add({_id => '9012', name => 'patrick'}), 'adding a record'; note("...upload"); - ok $store->bag->files('1234') + ok $store->bag->files('9012') ->upload(IO::File->new('t/data2/000/000/001/test.txt'), 'test1.txt'); - ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists (2)'; + ok -f 't/tmp/sidecar/000/009/012/test1.txt', 'test1.txt exists (2)'; note("...get"); - my $file = $store->bag->files('1234')->get("test1.txt"); + my $file = $store->bag->files('9012')->get("test1.txt"); ok $file; note("...stream"); - my $str = $store->bag->files('1234')->as_string_utf8($file); + my $str = $store->bag->files('9012')->as_string_utf8($file); ok $str , 'can stream the data'; @@ -149,4 +151,6 @@ note("Combined Hash + Simple sidecar"); is_deeply $array , [], 'got correct response'; } +path("t/tmp/sidecar")->remove_tree; + done_testing; diff --git a/t/Catmandu-Store-File-Memory-Bag.t b/t/Catmandu-Store-File-Memory-Bag.t index 1df93ad1a..1e7a5f3b1 100644 --- a/t/Catmandu-Store-File-Memory-Bag.t +++ b/t/Catmandu-Store-File-Memory-Bag.t @@ -23,11 +23,11 @@ my $index = $store->bag; ok $store , 'got a store'; ok $index , 'got an index'; -ok $index->add({_id => 1234}), 'adding bag `1234`'; +ok $index->add({_id => 8012}), 'adding bag `8012`'; -my $bag = $store->bag('1234'); +my $bag = $store->bag('8012'); -ok $bag , 'got bag(1234)'; +ok $bag , 'got bag(8012)'; note("add"); { diff --git a/t/Catmandu-Store-File-Multi-Bag.t b/t/Catmandu-Store-File-Multi-Bag.t index 8d4c59aea..da15a7f2a 100644 --- a/t/Catmandu-Store-File-Multi-Bag.t +++ b/t/Catmandu-Store-File-Multi-Bag.t @@ -5,6 +5,7 @@ use Test::More; use Test::Exception; use Catmandu::Store::File::Simple; use Catmandu::Store::File::Multi; +use Path::Tiny; use utf8; my $pkg; @@ -16,9 +17,12 @@ BEGIN { require_ok $pkg; +path("t/tmp/multi-bag/a")->mkpath; +path("t/tmp/multi-bag/b")->mkpath; + my $stores = [ - Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9), - Catmandu::Store::File::Simple->new(root => 't/data3', keysize => 9), + Catmandu::Store::File::Simple->new(root => 't/tmp/multi-bag/a', keysize => 9), + Catmandu::Store::File::Simple->new(root => 't/tmp/multi-bag/b', keysize => 9), ]; my $store = Catmandu::Store::File::Multi->new(stores => $stores); @@ -27,11 +31,11 @@ my $index = $store->index; ok $store , 'got a store'; ok $index , 'got an index'; -ok $index->add({_id => 1234}), 'adding bag `1234`'; +ok $index->add({_id => 7012}), 'adding bag `7012`'; -my $bag = $store->bag('1234'); +my $bag = $store->bag('7012'); -ok $bag , 'got bag(1234)'; +ok $bag , 'got bag(7012)'; note("add"); { @@ -42,9 +46,9 @@ note("add"); is $n1 , 16, '16 bytes'; - ok -f 't/data/000/001/234/test1.txt', 'test1.txt exists'; + ok -f 't/tmp/multi-bag/a/000/007/012/test1.txt', 'test1.txt exists'; - ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists'; + ok -f 't/tmp/multi-bag/b/000/007/012/test1.txt', 'test1.txt exists'; my $n2 = $bag->upload(IO::File->new('t/data2/000/000/002/test.txt'), 'test2.txt'); @@ -53,9 +57,9 @@ note("add"); is $n2 , 6, '6 bytes'; - ok -f 't/data/000/001/234/test2.txt', 'test2.txt exists'; + ok -f 't/tmp/multi-bag/a/000/007/012/test2.txt', 'test2.txt exists'; - ok -f 't/data3/000/001/234/test2.txt', 'test1.txt exists'; + ok -f 't/tmp/multi-bag/b/000/007/012/test2.txt', 'test1.txt exists'; my $n3 = $bag->upload(IO::File->new('t/data2/000/000/003/test.txt'), 'test3.txt'); @@ -64,9 +68,9 @@ note("add"); is $n3 , 6, '6 bytes'; - ok -f 't/data/000/001/234/test3.txt', 'test3.txt exists'; + ok -f 't/tmp/multi-bag/a/000/007/012/test3.txt', 'test3.txt exists'; - ok -f 't/data3/000/001/234/test3.txt', 'test1.txt exists'; + ok -f 't/tmp/multi-bag/b/000/007/012/test3.txt', 'test1.txt exists'; my $data = { _id => 'test4.txt', @@ -131,4 +135,7 @@ note("...delete_all (index)"); is_deeply $array , [], 'got correct response'; } +path("t/tmp/multi-bag/a")->remove_tree; +path("t/tmp/multi-bag/b")->remove_tree; + done_testing(); diff --git a/t/Catmandu-Store-File-Multi-Index.t b/t/Catmandu-Store-File-Multi-Index.t index 14b385945..50021ad0b 100644 --- a/t/Catmandu-Store-File-Multi-Index.t +++ b/t/Catmandu-Store-File-Multi-Index.t @@ -5,6 +5,7 @@ use Test::More; use Test::Exception; use Catmandu::Store::File::Simple; use Catmandu::Store::File::Multi; +use Path::Tiny; my $pkg; @@ -57,9 +58,12 @@ note("get"); } } +path("t/tmp/multi-index/a")->mkpath; +path("t/tmp/multi-index/b")->mkpath; + $stores = [ - Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9), - Catmandu::Store::File::Simple->new(root => 't/data3', keysize => 9), + Catmandu::Store::File::Simple->new(root => 't/tmp/multi-index/a', keysize => 9), + Catmandu::Store::File::Simple->new(root => 't/tmp/multi-index/b', keysize => 9), ]; $store = Catmandu::Store::File::Multi->new(stores => $stores); @@ -78,14 +82,14 @@ note("add"); ok $c , 'add(1234)'; - ok -d "t/data/000/001/234", 'found a container on disk'; + ok -d "t/tmp/multi-index/a/000/001/234", 'found a container on disk'; } note("delete"); { ok $index->delete('1234'), 'delete(1234)'; - ok !-d "t/data/000/001/234", 'container on disk was deleted'; + ok !-d "t/tmp/multi-index/a/000/001/234", 'container on disk was deleted'; } note("delete_all"); @@ -93,4 +97,7 @@ note("delete_all"); lives_ok {$index->delete_all()} 'delete_all'; } +path("t/tmp/multi-index/a")->remove_tree; +path("t/tmp/multi-index/b")->remove_tree; + done_testing(); diff --git a/t/Catmandu-Store-File-Multi.t b/t/Catmandu-Store-File-Multi.t index 2c3ce9353..036b0690f 100644 --- a/t/Catmandu-Store-File-Multi.t +++ b/t/Catmandu-Store-File-Multi.t @@ -6,6 +6,7 @@ use Test::More; use Test::Exception; use Catmandu::Store::File::Simple; use Catmandu::Store::Hash; +use Path::Tiny; use utf8; my $pkg; @@ -16,11 +17,14 @@ BEGIN { } require_ok $pkg; +path("t/tmp/multi/a")->mkpath; +path("t/tmp/multi/b")->mkpath; + note("Simple stores"); { my $stores = [ - Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9), - Catmandu::Store::File::Simple->new(root => 't/data3', keysize => 9), + Catmandu::Store::File::Simple->new(root => 't/tmp/multi/a', keysize => 9), + Catmandu::Store::File::Simple->new(root => 't/tmp/multi/b', keysize => 9), ]; my $store = $pkg->new(stores => $stores); @@ -30,25 +34,25 @@ note("Simple stores"); ok $index , 'got an index'; note("...exists"); - ok !$index->exists('1234'); + ok !$index->exists('6012'); note("...add"); - ok $index->add({_id => 1234}), 'adding bag `1234`'; + ok $index->add({_id => 6012}), 'adding bag `6012`'; - ok -d "t/data/000/001/234"; - ok -d "t/data3/000/001/234"; + ok -d "t/tmp/multi/a/000/006/012"; + ok -d "t/tmp/multi/b/000/006/012"; note("...bag"); - my $bag = $store->bag->files('1234'); + my $bag = $store->bag->files('6012'); - ok $bag , 'got bag(1234)'; + ok $bag , 'got bag(6012)'; note("...upload"); ok $bag->upload(IO::File->new('t/data2/000/000/001/test.txt'), 'test1.txt'); - ok -f 't/data/000/001/234/test1.txt', 'test1.txt exists (1)'; - ok -f 't/data3/000/001/234/test1.txt', 'test1.txt exists (2)'; + ok -f 't/tmp/multi/a/000/006/012/test1.txt', 'test1.txt exists (1)'; + ok -f 't/tmp/multi/b/000/006/012/test1.txt', 'test1.txt exists (2)'; note("...list"); my $array = [sort @{$bag->map(sub {shift->{_id}})->to_array}]; @@ -80,8 +84,8 @@ note("Simple stores"); is_deeply $array , [], 'got correct response'; - ok !-f 't/data/000/001/234/test1.txt', 'test1.txt doesnt exists (1)'; - ok !-f 't/data3/000/001/234/test1.txt', 'test1.txt doesnt exists (2)'; + ok !-f 't/tmp/multi/a/000/006/012/test1.txt', 'test1.txt doesnt exists (1)'; + ok !-f 't/tmp/multi/b/000/006/012/test1.txt', 'test1.txt doesnt exists (2)'; note("...delete_all (index)"); lives_ok {$index->delete_all()} 'delete_all'; @@ -91,4 +95,7 @@ note("Simple stores"); is_deeply $array , [], 'got correct response'; } +path("t/tmp/multi/a")->remove_tree; +path("t/tmp/multi/b")->remove_tree; + done_testing; diff --git a/t/Catmandu-Store-File-Simple-Bag.t b/t/Catmandu-Store-File-Simple-Bag.t index 186dc0b08..69a8ee793 100644 --- a/t/Catmandu-Store-File-Simple-Bag.t +++ b/t/Catmandu-Store-File-Simple-Bag.t @@ -5,6 +5,7 @@ use Test::More; use Test::Exception; use IO::String; use Catmandu::Store::File::Simple; +use Path::Tiny; use utf8; my $pkg; @@ -16,8 +17,10 @@ BEGIN { require_ok $pkg; +path("t/tmp/file-simple-bag")->mkpath; + my $store - = Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9); + = Catmandu::Store::File::Simple->new(root => 't/tmp/file-simple-bag', keysize => 9); my $index = $store->bag; ok $store , 'got a store'; @@ -38,7 +41,7 @@ note("add"); is $n1 , 16, '16 bytes'; - ok -f 't/data/000/001/234/test1.txt', 'test1.txt exists'; + ok -f 't/tmp/file-simple-bag/000/001/234/test1.txt', 'test1.txt exists'; my $n2 = $bag->upload(IO::File->new('t/data2/000/000/002/test.txt'), 'test2.txt'); @@ -47,7 +50,7 @@ note("add"); is $n2 , 6, '6 bytes'; - ok -f 't/data/000/001/234/test2.txt', 'test2.txt exists'; + ok -f 't/tmp/file-simple-bag/000/001/234/test2.txt', 'test2.txt exists'; my $n3 = $bag->upload(IO::File->new('t/data2/000/000/003/test.txt'), 'test3.txt'); @@ -56,7 +59,7 @@ note("add"); is $n3 , 6, '6 bytes'; - ok -f 't/data/000/001/234/test3.txt', 'test3.txt exists'; + ok -f 't/tmp/file-simple-bag/000/001/234/test3.txt', 'test3.txt exists'; my $data = { _id => 'test3.txt', @@ -120,4 +123,6 @@ note("delete_all"); is_deeply $array , [], 'got correct response'; } +path("t/tmp/file-simple-bag")->remove_tree; + done_testing(); diff --git a/t/Catmandu-Store-File-Simple-Index.t b/t/Catmandu-Store-File-Simple-Index.t index 2785fe3f9..c86e350cc 100644 --- a/t/Catmandu-Store-File-Simple-Index.t +++ b/t/Catmandu-Store-File-Simple-Index.t @@ -3,6 +3,7 @@ use strict; use warnings; use Test::More; use Test::Exception; +use Path::Tiny; use Catmandu::Store::File::Simple; my $pkg; @@ -54,7 +55,9 @@ note("get"); } } -$store = Catmandu::Store::File::Simple->new(root => 't/data', keysize => 9); +path("t/tmp/file-simple-index")->mkpath; + +$store = Catmandu::Store::File::Simple->new(root => 't/tmp/file-simple-index', keysize => 9); $index = $store->bag(); note("add"); @@ -70,14 +73,14 @@ note("add"); ok $c , 'add(1234)'; - ok -d "t/data/000/001/234", 'found a container on disk'; + ok -d "t/tmp/file-simple-index/000/001/234", 'found a container on disk'; } note("delete"); { ok $index->delete('1234'), 'delete(1234)'; - ok !-d "t/data/000/001/234", 'container on disk was deleted'; + ok !-d "t/tmp/file-simple-index/000/001/234", 'container on disk was deleted'; } note("delete_all"); @@ -85,4 +88,6 @@ note("delete_all"); lives_ok {$index->delete_all()} 'delete_all'; } +path("t/tmp/file-simple-index")->remove_tree; + done_testing(); diff --git a/t/data/.gitignore b/t/data/.gitignore deleted file mode 100644 index e69de29bb..000000000 diff --git a/t/data3/.gitignore b/t/data3/.gitignore deleted file mode 100644 index e69de29bb..000000000