Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #67 from brummett/db-full
Browse files Browse the repository at this point in the history
Return 503 if the database server can't make the database
  • Loading branch information
brummett committed Mar 18, 2015
2 parents 44ac1aa + 77c02d2 commit 9f5f23b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/rest-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Returns 201 and JSON in the body
}
The Location header will be the URL for this entity

Returns 503 if the database server was not able to create the requested database

-----------------------------------------------------

POST /databases?based_on=<template-name>
Expand All @@ -149,6 +151,7 @@ Returns 201 and JSON in the body
The Location header will be the URL for this entity

Returns 404 if there is no template with that name
Returns 503 if the database server was not able to create the requested database

---------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions lib/TestDbServer/DatabaseRoutes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ sub create {
$self->app->log->error('template not found');
$return_code = 404;

} elsif (ref($_) && $_->isa('Exception::CannotCreateDatabase')) {
$self->app->log->error("Cannot create database: $_");
$return_code = 503;

} else {
$self->app->log->fatal("_create_database_from_template: $_");
$return_code = 400;
Expand Down
19 changes: 19 additions & 0 deletions t/commands.t
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ subtest 'create database from template' => sub {
)->dropdb;
};

subtest 'failed create database throws exception' => sub {
plan tests => 1;

local *DBI::db::do = sub { die "Fake!" };

my $cmd = TestDbServer::Command::CreateDatabaseFromTemplate->new(
owner => undef,
host => $config->db_host,
port => $config->db_port,
template_name => $config->default_template_name,
schema => $schema,
superuser => $config->db_user,
);

throws_ok { $cmd->execute() }
'Exception::CannotCreateDatabase',
'Caught "CannotCreateDatabase" when create database dies';
};

subtest 'delete template' => sub {
plan tests => 4;

Expand Down

0 comments on commit 9f5f23b

Please sign in to comment.