Files
ubicloud/spec/routes/api/cli/pg/restore_spec.rb
Jeremy Evans b4e14bbe25 Ensure cli response bodies end with newline
Currently, response bodies mix trailing newline and no trailing
newline, and it kind of works because bin/ubi is written in Ruby
and uses IO#puts, which will automatically add a newline if the
string being printed does not end with a newline.  However,
other languages may not have similar behavior, and for consistency,
it is best if the server always uses newlines in cli responses.
2025-02-21 09:32:10 -08:00

24 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe Clover, "cli pg restore" do
before do
expect(Config).to receive(:postgres_service_project_id).and_return(@project.id).at_least(:once)
end
it "schedules a restore of the database to the given time" do
backup = Struct.new(:key, :last_modified)
restore_target = Time.now.utc
expect(MinioCluster).to receive(:[]).and_return(instance_double(MinioCluster, url: "dummy-url", root_certs: "dummy-certs")).at_least(:once)
expect(Minio::Client).to receive(:new).and_return(instance_double(Minio::Client, list_objects: [backup.new("basebackups_005/backup_stop_sentinel.json", restore_target - 10 * 60)])).at_least(:once)
cli(%w[pg eu-central-h1/test-pg create])
expect(PostgresResource.select_order_map(:name)).to eq %w[test-pg]
body = cli(%w[pg eu-central-h1/test-pg restore test-pg-2] << Time.now.utc)
expect(PostgresResource.select_order_map(:name)).to eq %w[test-pg test-pg-2]
pg = PostgresResource.first(name: "test-pg-2")
expect(body).to eq "Restored PostgreSQL database scheduled for creation with id: #{pg.ubid}\n"
end
end