App-MtAws

 view release on metacpan or  search on metacpan

t/unit/glacier/inventory_csv.t  view on Meta::CPAN

#!/usr/bin/env perl

# mt-aws-glacier - Amazon Glacier sync client
# Copyright (C) 2012-2014  Victor Efimov
# http://mt-aws.com (also http://vs-dev.com) vs@vs-dev.com
# License: GPLv3
#
# This file is part of "mt-aws-glacier"
#
#    mt-aws-glacier is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    mt-aws-glacier is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;
use Test::More tests => 805;
use Test::Deep;
use Carp;
use FindBin;
use Scalar::Util qw/weaken/;
use lib map { "$FindBin::RealBin/../$_" } qw{../lib ../../lib};
use TestUtils 'w_fatal';
use App::MtAws::Glacier::Inventory::CSV;




use Data::Dumper;

sub test_full_file
{
	my $a = shift;
	my $b = shift;
	my $data = App::MtAws::Glacier::Inventory::CSV->new($a)->get_archives();
	cmp_deeply $data, $b;
}

test_full_file <<'END',
ArchiveId ,ArchiveDescription , CreationDate,Size,SHA256TreeHash
a,b,c,d,e
END
[
	{'ArchiveId ' => 'a', 'ArchiveDescription ' =>'b', ' CreationDate'=>'c', Size => 'd', SHA256TreeHash => 'e'}
];

test_full_file <<'END',
ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash
a,b,c,d,e
END
[
	{ArchiveId => 'a', ArchiveDescription=>'b', CreationDate=>'c', Size => 'd', SHA256TreeHash => 'e'}
];

test_full_file "ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash\015\012a,b,c,d,e",
[
	{ArchiveId => 'a', ArchiveDescription=>'b', CreationDate=>'c', Size => 'd', SHA256TreeHash => 'e'}
];

test_full_file "ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash\015\012a,b,c,d,e\015\012",
[
	{ArchiveId => 'a', ArchiveDescription=>'b', CreationDate=>'c', Size => 'd', SHA256TreeHash => 'e'}
];

test_full_file "ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash\015\012a,b,c,d,e\012",
[
	{ArchiveId => 'a', ArchiveDescription=>'b', CreationDate=>'c', Size => 'd', SHA256TreeHash => 'e'}
];

test_full_file "ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash\015\012",[];
test_full_file "ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash\012",[];
test_full_file "ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash",[];


ok eval { test_full_file "ArchiveId,ArchiveDescription,AnotherField,CreationDate,Size,SHA256TreeHash",[]; 1 },
	"should allow new fields";
ok eval { test_full_file "zzz",[]; 1 },
	"should allow different fields";

ok ! eval { test_full_file "ArchiveId,ArchiveDescription,CreationDate,Size,SHA256TreeHash\na,b",[]; 1 };
like "$@", qr/Bad CSV line/i;



( run in 1.222 second using v1.01-cache-2.11-cpan-9789f410c06 )