Files
ubicloud/spec/routes/api/cli/lb/create_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

45 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.describe Clover, "cli lb create" do
before do
cli(%w[ps eu-central-h1/test-ps create])
@ps = PrivateSubnet.first
end
it "creates load balancer with no option" do
expect(LoadBalancer.count).to eq 0
body = cli(%W[lb eu-central-h1/test-lb create #{@ps.ubid} 12345 54321])
expect(LoadBalancer.count).to eq 1
lb = LoadBalancer.first
expect(lb).to be_a LoadBalancer
expect(lb.name).to eq "test-lb"
expect(lb.private_subnet_id).to eq @ps.id
expect(lb.src_port).to eq 12345
expect(lb.dst_port).to eq 54321
expect(lb.algorithm).to eq "round_robin"
expect(lb.health_check_protocol).to eq "http"
expect(lb.health_check_endpoint).to eq "/up"
expect(lb.stack).to eq "dual"
expect(body).to eq "Load balancer created with id: #{lb.ubid}\n"
end
it "creates load balancer with -aeps options" do
expect(LoadBalancer.count).to eq 0
body = cli(%W[lb eu-central-h1/test-lb create -a hash_based -e /up2 -p https -s ipv4 #{@ps.ubid} 1234 5432])
expect(LoadBalancer.count).to eq 1
lb = LoadBalancer.first
expect(lb).to be_a LoadBalancer
expect(lb.name).to eq "test-lb"
expect(lb.private_subnet_id).to eq @ps.id
expect(lb.src_port).to eq 1234
expect(lb.dst_port).to eq 5432
expect(lb.algorithm).to eq "hash_based"
expect(lb.health_check_protocol).to eq "https"
expect(lb.health_check_endpoint).to eq "/up2"
expect(lb.stack).to eq "ipv4"
expect(body).to eq "Load balancer created with id: #{lb.ubid}\n"
end
end