#!/usr/bin/env perl

use Test::Most;

use Path::Tiny 0.018;

use_ok 'File::Rotate::Simple';

my $dir  = Path::Tiny->tempdir;
my $base = 'test.log';
my $file = path( $dir, $base );

my $r = File::Rotate::Simple->new(
    file  => "$file",
    touch => 1,
);

isa_ok $r => 'File::Rotate::Simple';

subtest 'default accessors' => sub {
    is $r->file              => $file, 'file';
    is $r->if_missing        => 1,     'if_missing';
    is $r->max               => 0,     'max';
    is $r->age               => 0,     'age';
    is $r->extension_format  => '.%#', 'extension_format';
    is $r->replace_extension => undef, 'replace_extension';
    is $r->touch             => 1,     'touch';
};

ok !$file->exists || -l $file, "file does not exist";

my $secret = path( $dir, "secret.log" );

ok symlink( $secret, $file ), "created symlink to $secret";

ok -l $file, "file is a symlink";
ok !$secret->exists, "dangling symlink";
ok !$file->exists, "dangling symlink";

ok $r->rotate, "rotate";

my $next = path($file . ".1");
ok $next->exists || -l $next, "file was rotated to $next";

ok $file->exists, "file was touched";
ok !-l $file, "but file is not a link";
ok !$secret->exists, "link still dangling";




done_testing;
