F:R:Mock shared attribute changed semantics
[Fedora-Rebuild.git] / t / 11mock.t
blob1bfd0d6bf0454c70711b8a2306c6b692a2a344e7
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Test::Simple tests => (3 * 4 + 0 + 1 + 2) + (3) + (3);
6 use Fedora::Rebuild::Mock;
7 use File::Path;
8 use File::Spec;
9 use URI;
12 # Each call does 1 test.
13 sub expect_croak {
14 my ($arch, $repos) = @_;
16 my $mock;
17 eval {
18 no warnings 'all';
19 $mock = Fedora::Rebuild::Mock->new(
20 architecture => $arch,
21 repositories => $repos
25 ok ( $@ ne '', "architecure <$arch> is forbidden");
26 unlink $mock->config_file if defined $mock;
30 # Each call does 4 + <number_of_repositories> tests.
31 sub do_test {
32 my ($arch, $repos) = @_;
34 my $mock = Fedora::Rebuild::Mock->new(
35 architecture => $arch,
36 repositories => $repos
38 my ($directory, $root) = $mock->make_configuration;
40 ok(defined $directory, 'Method make_configuration returns the directory');
41 ok(defined $root, 'Method make_configuration returns the root name');
43 my $filename = File::Spec->catfile($directory, ($root . '.cfg'));
44 open(my $fh, '<', $filename);
45 my $content = '';
46 while(<$fh>) {
47 $content .= $_;
48 if (/config_opts\['target_arch'\]\s*=\s*'([^']*)'/) {
49 ok ( ($1 eq $arch),
50 "target architecture: expected=<$arch> got=<$1>")
52 if (/config_opts\['legal_host_arches'\]\s*=\s*\('([^']*)',\)/) {
53 ok ( ($1 eq $arch),
54 "host architectures: expected=<$arch> got=<$1>")
57 close($fh);
59 for (@$repos) {
60 my $repo = URI->new($_);
61 ok ( $content =~ /[^#]*baseurl\s*=\s*\Q$repo\E/,
62 "$repo is referrenced");
65 File::Path::remove_tree($directory);
69 do_test('a', [ ]);
70 do_test('a', [ 'http://example.com/' ]);
71 do_test('a', [ 'http://1.example.com/', 'http://2.example.com/' ]);
73 expect_croak(q{'}, []);
74 expect_croak(q{"}, []);
75 expect_croak(qq{\n}, []);
77 # Shared mock caches
79 my ($arch, $repos) = ('q', [ 'http://example.com/'] );
81 my ($directory1, $root1) = Fedora::Rebuild::Mock->new(
82 architecture => $arch,
83 repositories => $repos,
84 shared => 1
85 )->make_configuration;
87 my $filename = File::Spec->catfile($directory1, ($root1 . '.cfg'));
88 open(my $fh, '<', $filename);
89 my $content1 = '';
90 while(<$fh>) { $content1 .= $_; }
91 close($fh);
93 for my $identifier (qw(ccache_enable yum_cache_enable root_cache_enable)) {
94 ok ($content1 =~ /\b\Q$identifier\E'\s*\]\s*=\s*True\b/,
95 "shared mock has enabled $identifier");
98 File::Path::remove_tree($directory1);