#!/usr/bin/perl

use warnings;
use strict;

use File::stat;
use Test::More;

sub assert_present {
	my ($name) = @_;
	ok(-d "/home/e-$name");
	ok(-f "/home/e-$name/ikiwiki.setup");
	ok(-f "/home/e-$name/public_html/ikiwiki/index.html");

	my $uid = getpwnam("e-$name");
	my $stat = stat("/home/e-$name");
	is($stat->uid, $uid);
}

sub assert_absent {
	my ($name) = @_;
	ok(! -e "/home/e-$name");
}

# This assumes that ikiwiki-hosting.conf still has prefix_e=example.com.
ok(! system(qw(ikisite create foo.example.com --admin=root@localhost)));
assert_present('foo');

my $backup = $ENV{AUTOPKGTEST_TMP}.'/backup';

ok(! system(qw(ikisite backup), '--filename='.$backup, qw(foo.example.com)));
ok(! system(qw(ikisite compact foo.example.com)));
ok(! system(qw(ikisite rename foo.example.com baz.example.com)));
ok(! system(qw(ikisite restore foo.example.com), '--filename='.$backup));
ok(! system(qw(ikisite branch foo.example.com bar.example.com)));

ok(! system(qw(ikisite delete foo.example.com)));
ok(! system(qw(ikisite delete bar.example.com)));
ok(! system(qw(ikisite delete baz.example.com)));
assert_absent('foo');
assert_absent('bar');
assert_absent('baz');

done_testing;
