summaryrefslogtreecommitdiff
path: root/t/11_utils.t
blob: 3925e0d6a83ade64581507806886209c7468fc13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl

use 5.028;
use strict;
use warnings;
use lib 't/lib';

use Cwd qw(realpath);
use Test::More;
use Git::Annex;
use File::Spec::Functions qw(catfile rel2abs);
use t::Setup;
use t::Util;
use Storable;
use Data::Compare;
use File::chdir;
use File::Basename qw(basename);

plan skip_all => "git-annex not available" unless git_annex_available;

with_temp_annexes {
    my $temp   = shift;
    my $annex  = Git::Annex->new("source1");
    my $annex2 = Git::Annex->new("source2");

    my $unused_info = catfile($temp, qw(source1 .git annex unused_info));
    is $annex->_git_path("blah", "foo"),
      catfile($temp, qw(source1 .git blah foo)),
      "_git_path resolves a path";
    is $annex->_unused_cache, $unused_info,
      "_unused_cache resolves to correct path";
    $annex->{_unused} = { foo => "bar" };
    $annex->_store_unused_cache;
    ok Compare($annex->{_unused}, retrieve $unused_info),
      "_store_unused_cache stores the cache";
    $annex->_clear_unused_cache;
    ok !exists $annex->{_unused}, "_clear_unused_cache clears unused hashref";
    ok !-f $unused_info, "_clear_unused_cache deletes the cache";

    {
        local $CWD = "source2";
        my $contentlocation = realpath rel2abs readlink "other";
        my $key             = basename readlink "other";
        is $annex2->abs_contentlocation($key), $contentlocation,
          "it returns an absolute path to the content for other";
        is $annex2->abs_contentlocation("foo"), undef,
          "it returns undef for a nonsense key";
    }
};

done_testing;