ubicloud/spec/routes/api/cli/pg/create_spec.rb
Jeremy Evans 5e67c45687 Allow creating a PostgreSQL database without firewall rules in api/sdk/cli
The reason for allowing this is it allows you to create a locked-down
PostgreSQL database without parsing output of previous commands.
Previously, to create a locked-down database, you needed to create the
database, then remove the default firewall rules for it, then add your
own. Using this, you add the database without rules, and then add the
rules you need.
2025-09-03 02:23:35 +09:00

45 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe Clover, "cli pg create" do
before do
expect(Config).to receive(:postgres_service_project_id).and_return(@project.id).at_least(:once)
end
it "creates PostgreSQL database with no options" do
expect(PostgresResource.count).to eq 0
body = cli(%w[pg eu-central-h1/test-pg create -s standard-2 -S 64])
expect(PostgresResource.count).to eq 1
pg = PostgresResource.first
expect(pg).to be_a PostgresResource
expect(pg.name).to eq "test-pg"
expect(pg.display_location).to eq "eu-central-h1"
expect(pg.target_vm_size).to eq "standard-2"
expect(pg.target_storage_size_gib).to eq 64
expect(pg.ha_type).to eq "none"
expect(pg.version).to eq "17"
expect(pg.flavor).to eq "standard"
expect(PostgresFirewallRule.count).to eq 2
expect(pg.tags).to eq([])
expect(body).to eq "PostgreSQL database created with id: #{pg.ubid}\n"
end
it "creates PostgreSQL database with all options" do
expect(PostgresResource.count).to eq 0
body = cli(%w[pg eu-central-h1/test-pg create -s standard-4 -S 128 -h async -v 17 -f paradedb -R -t foo=bar,baz=quux])
expect(PostgresResource.count).to eq 1
pg = PostgresResource.first
expect(pg).to be_a PostgresResource
expect(pg.name).to eq "test-pg"
expect(pg.display_location).to eq "eu-central-h1"
expect(pg.target_vm_size).to eq "standard-4"
expect(pg.target_storage_size_gib).to eq 128
expect(pg.ha_type).to eq "async"
expect(pg.version).to eq "17"
expect(pg.flavor).to eq "paradedb"
expect(PostgresFirewallRule.count).to eq 0
expect(pg.tags).to eq([{"key" => "foo", "value" => "bar"}, {"key" => "baz", "value" => "quux"}])
expect(body).to eq "PostgreSQL database created with id: #{pg.ubid}\n"
end
end