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.
50 lines
1.8 KiB
Ruby
50 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../spec_helper"
|
|
|
|
RSpec.describe Clover, "cli lb update" do
|
|
before do
|
|
cli(%w[vm eu-central-h1/test-vm create a])
|
|
cli(%w[vm eu-central-h1/test-vm2 create b])
|
|
@vm1, @vm2 = Vm.all
|
|
cli(%w[ps eu-central-h1/test-ps create])
|
|
@ps = PrivateSubnet.first
|
|
cli(%W[lb eu-central-h1/test-lb create #{@ps.ubid} 12345 54321])
|
|
@lb = LoadBalancer.first
|
|
@lb.add_vm(@vm1)
|
|
end
|
|
|
|
it "updates the load balancer" do
|
|
expect(@lb.vms.map(&:ubid)).to eq [@vm1.ubid]
|
|
expect(cli(%W[lb eu-central-h1/test-lb update hash_based 1234 5432 /up2 #{@vm1.ubid}])).to eq "Updated load balancer with id #{@lb.ubid}\n"
|
|
@lb.reload
|
|
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_endpoint).to eq "/up2"
|
|
expect(@lb.vms.map(&:ubid)).to eq [@vm1.ubid]
|
|
end
|
|
|
|
it "adds new VMs the load balancer" do
|
|
expect(@lb.vms.map(&:ubid)).to eq [@vm1.ubid]
|
|
expect(cli(%W[lb eu-central-h1/test-lb update hash_based 1234 5432 /up2 #{@vm1.ubid} #{@vm2.ubid}])).to eq "Updated load balancer with id #{@lb.ubid}\n"
|
|
@lb.reload
|
|
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_endpoint).to eq "/up2"
|
|
expect(@lb.vms.map(&:ubid).sort).to eq [@vm1.ubid, @vm2.ubid].sort
|
|
end
|
|
|
|
it "removes VMs not given from the load balancer" do
|
|
expect(@lb.vms.map(&:ubid)).to eq [@vm1.ubid]
|
|
expect(cli(%W[lb eu-central-h1/test-lb update hash_based 1234 5432 /up2])).to eq "Updated load balancer with id #{@lb.ubid}\n"
|
|
@lb.reload
|
|
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_endpoint).to eq "/up2"
|
|
expect(@lb.vms).to be_empty
|
|
end
|
|
end
|