Files
ubicloud/spec/routes/api/cli/pg/show_spec.rb
Jeremy Evans 27c84a96b3 Add more fields to pg show cli
This adds fields added to the api since the cli was added:

* maintenance-window-start-at
* read-replica
* parent (shown in location/name format)
* read-replicas (shown in location/name format)

The api includes much more information about the read replicas, but
I'm not sure sure how much of this information is useful. If we want
to expose that information in the cli, we probably need to add an
-r option so you can control which fields get displayed.
2025-08-19 09:36:13 -07:00

94 lines
3.0 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe Clover, "cli pg show" do
before do
expect(Config).to receive(:postgres_service_project_id).and_return(@project.id).at_least(:once)
@pg = Prog::Postgres::PostgresResourceNexus.assemble(
project_id: @project.id,
location_id: Location::HETZNER_FSN1_ID,
name: "test-pg",
target_vm_size: "standard-2",
target_storage_size_gib: 64
).subject
@ref = [@pg.display_location, @pg.name].join("/")
end
it "shows information for PostgreSQL database" do
expect(Config).to receive(:postgres_service_hostname).and_return("pg.example.com").at_least(:once)
@dns_zone = DnsZone.new
expect(Prog::Postgres::PostgresResourceNexus).to receive(:dns_zone).and_return(@dns_zone).at_least(:once)
@pg.add_metric_destination(username: "md-user", password: "1", url: "https://md.example.com")
@pg.update(root_cert_1: "a", root_cert_2: "b")
@pg.representative_server.vm.add_vm_storage_volume(boot: false, size_gib: 64, disk_index: 0)
expect(cli(%W[pg #{@ref} show])).to eq <<~END
id: #{@pg.ubid}
name: test-pg
state: creating
location: eu-central-h1
vm_size: standard-2
target_vm_size: standard-2
storage_size_gib: 64
target_storage_size_gib: 64
version: 17
ha_type: none
flavor: standard
connection_string: postgres://postgres:#{@pg.superuser_password}@test-pg.#{@pg.ubid}.pg.example.com:5432/postgres?sslmode=require
primary: true
earliest_restore_time:
maintenance_window_start_at:
read_replica: false
parent:
tags:
firewall rules:
1: #{@pg.firewall_rules[0].ubid} 0.0.0.0/0
metric destinations:
1: #{@pg.metric_destinations[0].ubid} md-user https://md.example.com
read replicas:
CA certificates:
a
b
END
@pg.update(parent_id: @pg.id)
expect(cli(%W[pg #{@ref} show])).to eq <<~END
id: #{@pg.ubid}
name: test-pg
state: creating
location: eu-central-h1
vm_size: standard-2
target_vm_size: standard-2
storage_size_gib: 64
target_storage_size_gib: 64
version: 17
ha_type: none
flavor: standard
connection_string: postgres://postgres:#{@pg.superuser_password}@test-pg.#{@pg.ubid}.pg.example.com:5432/postgres?sslmode=require
primary: true
earliest_restore_time:
maintenance_window_start_at:
read_replica: true
parent: eu-central-h1/test-pg
tags:
firewall rules:
1: #{@pg.firewall_rules[0].ubid} 0.0.0.0/0
metric destinations:
1: #{@pg.metric_destinations[0].ubid} md-user https://md.example.com
read replicas:
eu-central-h1/test-pg
CA certificates:
a
b
END
end
it "-f option controls which fields are shown for the PostgreSQL database" do
expect(cli(%W[pg #{@ref} show -f id,name])).to eq <<~END
id: #{@pg.ubid}
name: test-pg
END
end
end