Skip to content
Newer
Older
100644 91 lines (64 sloc) 2.41 KB
0a0d97b @wchristian initial commit
authored Sep 26, 2010
1 #!/usr/bin/perl
2 use Modern::Perl;
3
4 use Test::Most qw( die defer_plan );
5
6 run_tests();
7 all_done();
8
9 exit;
10
11 ###############################################################################
12
13 sub run_tests {
14 BEGIN { use_ok( 'Parallel::Downloader', qw( download_in_parallel ) ); }
15
16 can_ok( 'Parallel::Downloader', qw( download_in_parallel ) );
17
18 #$Parallel::Downloader::talk = 0;
19
20 my @downloads = prepare_downloads();
21
22 my @results = download_in_parallel( @downloads );
23
24 is( @results, 5, 'got 5 download results' );
25
26 like( $results[0], qr/<xml/, 'first download returned xml data to memory' );
27
28 return;
29 }
30
31 sub prepare_downloads {
32 my $store_dir = "./test/";
33 my $base_url = "http://eve-metrics.com/api/history.xml";
34
35 my @downloads = (
36 # basic GET request which gets replaced with the downloaded content and returned
37 "http://eve-metrics.com/api/history.xml?type_ids=39&region_ids=10000032",
38
39 # GET request with the content being stored as a file, gets updated with results and returned
40 {
41 url => "$base_url?type_ids=36&region_ids=10000032",
42 path => $store_dir."36_10000032",
43 store => 'file',
44 name => '36',
45 },
46
47 # GET request with the content being stored in the hash itself, gets updated with results and returned
48 {
49 url => "$base_url?type_ids=25896&region_ids=10000032",
50 store => 'memory',
51 name => '25896',
52 },
53
54 # POST request with the content being stored as a file, gets updated with results and returned
55 {
56 url => $base_url,
57 params => { type_ids => 37, region_ids => 10000032 },
58 path => $store_dir."37_10000032",
59 store => 'file',
60 name => '37',
61 },
62
63 # POST request with the content being stored in the hash itself, gets updated with results and returned
64 {
65 url => $base_url,
66 params => { type_ids => 38, region_ids => 10000032 },
67 store => 'memory',
68 name => '38',
69 },
70 );
71
72 return @downloads;
73 }
74
75 sub prepare_download_to_file {
76 my ( $file, $base_url, $store_dir ) = @_;
77
78 my %download = (
79 url => "$base_url$file",
80 path => "$store_dir$file",
81 store => 'file',
82 name => $file,
83 );
84
85 return \%download;
86 }
87
88
89
90
Something went wrong with that request. Please try again.