Skip to content

Commit

Permalink
Move some basic.t tests into more specific .t files
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Apr 16, 2012
1 parent 12b1335 commit f38ed43
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 44 deletions.
8 changes: 8 additions & 0 deletions t/api_domain_setup.t
Expand Up @@ -17,6 +17,7 @@ my $domain = test_domain_name;

my $schema = PowerDNS::API::schema();
ok(my $account = setup_user, 'setup account');
ok(my $account2 = setup_user, 'setup account 2');

ok(my $r = api_call(PUT => "domain/$domain", { hostmaster => 'ask@example.com', user => $account }), 'setup new domain');
$t->status_is(201, 'ok, created');
Expand All @@ -35,9 +36,16 @@ ok($r = api_call(PUT => "domain/$domain", { user => $account }), 'setup new doma
$t->status_is(201);
is($r->{domain}->{name}, lc $domain, "got setup as lowercase domain");

ok($r = api_call(PUT => "domain/sub2.$domain", { user => $account2 }), 'setup sub-domain with another account');
$t->status_is(403, 'forbidden');

ok($r = api_call(PUT => "domain/sub.$domain", { user => $account }), 'setup sub-domain with the same account');
$t->status_is(201, 'created');

#diag pp($r);

ok($account->delete, 'deleted account again');
ok($account2->delete, 'deleted second account');

done_testing();
exit;
73 changes: 73 additions & 0 deletions t/api_record.t
@@ -0,0 +1,73 @@
use Test::More;
use strict;
use warnings;
use Data::Dump qw(pp);

use Test::Mojo;
my $t = Test::Mojo->new('PowerDNS::API');

$Carp::Verbose = 1;

use lib 't';
use TestUtils;

$TestUtils::t = $t;

my $r;

my $domain = test_domain_name;

my $schema = PowerDNS::API::schema();
ok(my $account = setup_user, 'setup account');
ok(my $account2 = setup_user, 'setup account 2');

$TestUtils::current_user = $account;

ok($r = api_call(PUT => "domain/$domain", { user => $account }), 'setup new domain');
$t->status_is(201, 'ok, created');

ok($r = api_call(POST => "record/$domain", { type => 'NS', name => '', content => 'ns1.example.com' }), 'setup NS record');
$t->status_is(201);
ok($r->{record}->{id}, 'got an ID');
is($r->{record}->{type}, 'NS', 'is an NS record');

ok($r = api_call(POST => "record/$domain", { type => 'SOA', name => '', content => '' }), 'Add a second SOA record');
$t->status_is(406);

ok($r = api_call(POST => "record/$domain", { type => 'A', name => 'www', content => '10.0.0.1' }), 'setup A record');
ok($r->{record}->{id}, 'got an ID');
is($r->{record}->{content}, '10.0.0.1', 'correct content');

my $id = $r->{record}->{id};

ok($r = api_call(PUT => "record/$domain/$id", { content => '10.0.0.2' }), 'change A record');
is($r->{record}->{content}, '10.0.0.2', 'correct content');


ok( $r = api_call(
POST => "record/$domain",
{ type => 'TXT',
name => '_spf',
content => 'some text goes here',
ttl => 600
}
),
'setup TXT record with TTL'
);
ok($r->{record}->{id}, 'got an ID');
is($r->{record}->{ttl}, 600, 'correct TTL');

ok($r = api_call(GET => "domain/$domain", { type => 'A', name => 'www' }), "Get records with filter");
ok($r->{domain}, "got domain back");
is($r->{domain}->{name}, $domain, 'got the right domain');
is($r->{records}->[0]->{name}, 'www', 'got the right record name');

ok($r = api_call(DELETE => "record/$domain/$id"), 'delete TXT record');

$id = $r->{record}->{id};

ok($account->delete, 'deleted account again');
ok($account2->delete, 'deleted second account');

done_testing();
exit;
44 changes: 0 additions & 44 deletions t/basic.t
Expand Up @@ -65,50 +65,6 @@ is($r->{domain}->{type}, 'SLAVE', 'now slave');
ok($r = api_call(POST => "domain/$domain", { type => 'master' }), "Change domain back to be master");
is($r->{domain}->{type}, 'MASTER', 'now master');

ok($r = api_call(POST => "record/$domain", { type => 'NS', name => '', content => 'ns1.example.com' }), 'setup NS record');
ok($r->{record}->{id}, 'got an ID');
is($r->{record}->{type}, 'NS', 'is an NS record');

ok($r = api_call(POST => "record/$domain", { type => 'SOA', name => '', content => '' }), 'Add a second SOA record');
$t->status_is(406, 'Not acceptable');

ok($r = api_call(POST => "record/$domain", { type => 'A', name => 'www', content => '10.0.0.1' }), 'setup A record');
ok($r->{record}->{id}, 'got an ID');
is($r->{record}->{content}, '10.0.0.1', 'correct content');

my $id = $r->{record}->{id};

ok($r = api_call(PUT => "record/$domain/$id", { content => '10.0.0.2' }), 'change A record');
is($r->{record}->{content}, '10.0.0.2', 'correct content');


ok( $r = api_call(
POST => "record/$domain",
{ type => 'TXT',
name => '_spf',
content => 'some text goes here',
ttl => 600
}
),
'setup TXT record with TTL'
);
ok($r->{record}->{id}, 'got an ID');
is($r->{record}->{ttl}, 600, 'correct TTL');

ok($r = api_call(GET => "domain/$domain", { type => 'A', name => 'www' }), "Get records with filter");
ok($r->{domain}, "got domain back");
is($r->{domain}->{name}, $domain, 'got the right domain');
is($r->{records}->[0]->{name}, 'www', 'got the right record name');

ok($r = api_call(DELETE => "record/$domain/$id"), 'delete TXT record');

$id = $r->{record}->{id};

ok($r = api_call(PUT => "domain/sub2.$domain", { user => $account2 }), 'setup sub-domain with another account');
$t->status_is(403, 'forbidden');

ok($r = api_call(PUT => "domain/sub.$domain", { user => $account }), 'setup sub-domain with the same account');
$t->status_is(201, 'created');

# diag pp($r);

Expand Down

0 comments on commit f38ed43

Please sign in to comment.