Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Handle backup schedule gracefully when app has no databases; add specs #1600

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/heroku/command/pg_backups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ def unschedule_backups
def list_schedules
validate_arguments!
attachment = arbitrary_app_db
if attachment.nil?
abort("#{app} has no heroku-postgresql databases.")
end

schedules = hpg_client(attachment).schedules
if schedules.empty?
Expand Down
41 changes: 41 additions & 0 deletions spec/heroku/command/pg_backups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,47 @@ module Heroku::Command
end
end

describe "heroku pg:backups schedules" do
let(:schedules) do
[ { name: 'HEROKU_POSTGRESQL_GREEN_URL',
uuid: 'ffffffff-ffff-ffff-ffff-ffffffffffff',
hour: 4, timezone: 'US/Pacific' },
{ name: 'DATABASE_URL',
uuid: 'ffffffff-ffff-ffff-ffff-fffffffffffe',
hour: 20, timezone: 'UTC' } ]
end

it "lists the existing schedules" do
allow_any_instance_of(Heroku::Helpers::HerokuPostgresql::Resolver)
.to receive(:app_attachments).and_return(example_attachments)
stub_pg.schedules.returns(schedules)
stderr, stdout = execute("pg:backups schedules")
expect(stderr).to be_empty
expect(stdout).to eq(<<-EOF)
=== Backup Schedules
HEROKU_POSTGRESQL_GREEN_URL: daily at 4:00 (US/Pacific)
DATABASE_URL: daily at 20:00 (UTC)
EOF
end

it "reports there are no schedules when none exist" do
allow_any_instance_of(Heroku::Helpers::HerokuPostgresql::Resolver)
.to receive(:app_attachments).and_return(example_attachments)
stub_pg.schedules.returns([])
stderr, stdout = execute("pg:backups schedules")
expect(stderr).to be_empty
expect(stdout).to match(/No backup schedules found/)
end

it "reports there are no databases when the app has none" do
allow_any_instance_of(Heroku::Helpers::HerokuPostgresql::Resolver)
.to receive(:app_attachments).and_return([])
stderr, stdout = execute("pg:backups schedules")
expect(stderr).to match(/example has no heroku-postgresql databases/)
expect(stdout).to be_empty
end
end

describe "heroku pg:backups unschedule" do
let(:schedules) do
[ { name: 'HEROKU_POSTGRESQL_GREEN_URL',
Expand Down