ubicloud/spec/routes/api/cli/pg/rename_spec.rb
Jeremy Evans 90078b3bfc Avoid renaming objects if the name didn't change
Before, worst case scenario was an extra database write. Now, it
would perform an unnecessary certificate change for postgres
resources. It's best to just skip the updates if the name is the
same.
2025-09-17 01:43:20 +09:00

24 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe Clover, "cli pg rename" do
it "renames PostgreSQL database" do
expect(Config).to receive(:postgres_service_project_id).and_return(@project.id).at_least(:once)
cli(%w[pg eu-central-h1/test-pg create -s standard-2 -S 64])
pg = PostgresResource.first
expect(pg.semaphores_dataset.all).to eq []
expect(cli(%w[pg eu-central-h1/test-pg rename new-name])).to eq "PostgreSQL database renamed to new-name\n"
expect(pg.reload.name).to eq "new-name"
expect(pg.semaphores_dataset.select_order_map(:name)).to eq %w[refresh_certificates refresh_dns_record]
end
it "does not set semaphores if there is no actual rename" do
expect(Config).to receive(:postgres_service_project_id).and_return(@project.id).at_least(:once)
cli(%w[pg eu-central-h1/test-pg create -s standard-2 -S 64])
pg = PostgresResource.first
expect(cli(%w[pg eu-central-h1/test-pg rename test-pg])).to eq "PostgreSQL database renamed to test-pg\n"
expect(pg.reload.name).to eq "test-pg"
expect(pg.semaphores_dataset.all).to eq []
end
end