Add tests for Zeal::Feed
authorMarius Gavrilescu <marius@ieval.ro>
Tue, 30 Dec 2014 21:11:38 +0000 (23:11 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Tue, 30 Dec 2014 21:11:38 +0000 (23:11 +0200)
MANIFEST
t/Zeal-Feed.t [new file with mode: 0644]
t/a.tar [new file with mode: 0644]
t/a.tar.bz2 [new file with mode: 0644]
t/a.tar.gz [new file with mode: 0644]
t/feed.xml [new file with mode: 0644]

index 4ca629c52a229e552bdadea0c4353f85d5d6806f..a7300bdcb178625d5e37b6b2b8d512bfbc9ff406 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -6,6 +6,9 @@ lib/Zeal/Feed.pm
 Makefile.PL
 MANIFEST
 README
+t/a.tar
+t/a.tar.bz2
+t/a.tar.gz
 t/ds/a.docset/Contents/Info.plist
 t/ds/a.docset/Contents/Resources/docSet.dsidx
 t/ds/a.docset/Contents/Resources/Documents/about.html
@@ -19,7 +22,9 @@ t/ds/c.docset/Contents/Resources/docSet.dsidx
 t/ds/c.docset/Contents/Resources/Documents/category.html
 t/ds/c.docset/Contents/Resources/Documents/class.html
 t/ds/dummy-file
+t/feed.xml
 t/mkindex.pl
 t/perlcritic.t
 t/perlcriticrc
 t/Zeal.t
+t/Zeal-Feed.t
diff --git a/t/Zeal-Feed.t b/t/Zeal-Feed.t
new file mode 100644 (file)
index 0000000..9113bc9
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Test::More tests => 23;
+BEGIN { use_ok('Zeal::Feed') };
+
+my $feed = Zeal::Feed->new_from_file('t/feed.xml');
+is $feed->version, '1.2.3', 'feed version is 1.2.3';
+my @urls = sort $feed->urls;
+my $url_re = qr,^http://srv[12]\.example\.com/feed\.tar\.gz$,;
+like $urls[$_-1], $url_re, "feed url $_ is correct" for 1, 2;
+like $feed->url, $url_re, 'feed random url is correct';
+
+use File::Temp qw/tempdir/;
+
+sub test_unpack {
+       my ($arch) = @_;
+       my $dir = tempdir 'zeal-testXXXX', TMPDIR => 1, CLEANUP => 1;
+       note "Testing unpack of $arch";
+       Zeal::Feed::_unpack_tar_to_dir($arch, $dir);
+       ok -d "$dir/a.docset", 'Root directory of unpacked docset exists';
+       ok -f "$dir/a.docset/Contents/Info.plist", 'Info.plist exists';
+}
+
+note "Testing unpack with default tar";
+test_unpack $_ for 't/a.tar', 't/a.tar.gz', 't/a.tar.bz2';
+note "Testing unpack with Archive::Tar by env variable";
+$ENV{ZEAL_USE_INTERNAL_TAR} = 1;
+test_unpack $_ for 't/a.tar', 't/a.tar.gz', 't/a.tar.bz2';
+note "Testing unpack with Archive::Tar by clearing PATH";
+$ENV{ZEAL_USE_INTERNAL_TAR} = 0;
+$ENV{PATH} = '';
+test_unpack $_ for 't/a.tar', 't/a.tar.gz', 't/a.tar.bz2';
diff --git a/t/a.tar b/t/a.tar
new file mode 100644 (file)
index 0000000..362cc8c
Binary files /dev/null and b/t/a.tar differ
diff --git a/t/a.tar.bz2 b/t/a.tar.bz2
new file mode 100644 (file)
index 0000000..41454e8
Binary files /dev/null and b/t/a.tar.bz2 differ
diff --git a/t/a.tar.gz b/t/a.tar.gz
new file mode 100644 (file)
index 0000000..1c8d473
Binary files /dev/null and b/t/a.tar.gz differ
diff --git a/t/feed.xml b/t/feed.xml
new file mode 100644 (file)
index 0000000..3ad8cb2
--- /dev/null
@@ -0,0 +1,5 @@
+<entry>
+  <version>1.2.3</version>
+  <url>http://srv1.example.com/feed.tar.gz</url>
+  <url>http://srv2.example.com/feed.tar.gz</url>
+</entry>
This page took 0.013914 seconds and 4 git commands to generate.