Adapt to mock-1.4.1-1.fc25
[Fedora-Rebuild.git] / t / 14repository.t
blob55461b0226314a52422dcfaeddb9778f3591f570
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Test::More tests => 9;
6 use Fedora::Rebuild::Repository;
7 use File::Temp ();
8 use File::Spec ();
9 use HTTP::Tiny ();
10 use URI ();
11 use URI::Escape ();
13 my $directory = File::Temp::tempdir(CLEANUP => 1);
14 ok($directory, 'temporary directory created');
16 my $repository = Fedora::Rebuild::Repository->new(path=>$directory);
17 ok($repository, 'Fedora::Rebuild::Repository object created');
19 my $url = $repository->start;
20 ok($url, 'repository server started');
22 my $file_name = 'c++';
23 my $file_content = '42';
24 my $file = File::Spec->catfile($directory, $file_name);
25 ok(open(my $fh, '>', $file), "file '$file_name' created");
26 print $fh $file_content;
27 ok(close($fh), "content written");
29 my $file_name_escaped = URI::Escape::uri_escape_utf8($file_name);
30 my $response = HTTP::Tiny->new->get(URI->new_abs($file_name_escaped, $url));
31 ok($response, "GET request for escaped '$file_name_escaped' sent");
33 ok($response->{success},
34 "file '$file_name' retrieved: $response->{status} $response->{reason}");
35 is($response->{content}, $file_content, 'file content matches');
37 $repository->stop;
38 pass('repository server stopped');