WIP: fixup specs after rebase

This commit is contained in:
Jesse Scott 2020-09-21 16:59:04 -07:00
parent e269d71fea
commit 8546c1c4b6
No known key found for this signature in database
GPG key ID: 285826E26E0AAD93

View file

@ -247,32 +247,50 @@ describe Utils do
describe '#pretty_print_hosts' do
let(:url) { 'http://pooler.example.com' }
let(:verbose) { nil }
let(:print_to_stderr) { false }
it 'prints a vmpooler output with host fqdn, template and duration info' do
hostname = 'mcpy42eqjxli9g2'
response_body = { hostname => {
before(:each) do
allow(service).to receive(:query)
.with(anything, hostname)
.and_return(response_body)
end
subject { Utils.pretty_print_hosts(verbose, service, hostname, print_to_stderr) }
describe 'with vmpooler service' do
let(:service) { Service.new(MockOptions.new, 'url' => url) }
let(:hostname) { 'mcpy42eqjxli9g2' }
let(:domain) { 'delivery.mycompany.net' }
let(:fqdn) { [hostname, domain].join('.') }
let(:response_body) do
{
hostname => {
'template' => 'ubuntu-1604-x86_64',
'lifetime' => 12,
'running' => 9.66,
'state' => 'running',
'ip' => '127.0.0.1',
'domain' => 'delivery.mycompany.net',
} }
output = '- mcpy42eqjxli9g2.delivery.mycompany.net (ubuntu-1604-x86_64, 9.66/12 hours)'
expect(STDOUT).to receive(:puts).with(output)
service = Service.new(MockOptions.new, 'url' => url)
allow(service).to receive(:query)
.with(nil, hostname)
.and_return(response_body)
Utils.pretty_print_hosts(nil, service, hostname)
'domain' => domain,
}
}
end
it 'prints a vmpooler output with host fqdn, template, duration info, and tags when supplied' do
hostname = 'aiydvzpg23r415q'
response_body = { hostname => {
let(:default_output) { "- #{fqdn} (ubuntu-1604-x86_64, 9.66/12 hours)" }
it 'prints output with host fqdn, template and duration info' do
expect(STDOUT).to receive(:puts).with(default_output)
subject
end
context 'when tags are supplied' do
let(:hostname) { 'aiydvzpg23r415q' }
let(:response_body) do
{
hostname => {
'template' => 'redhat-7-x86_64',
'lifetime' => 48,
'running' => 7.67,
@ -282,60 +300,140 @@ describe Utils do
'role' => 'agent',
},
'ip' => '127.0.0.1',
'domain' => 'delivery.mycompany.net',
} }
output = '- aiydvzpg23r415q.delivery.mycompany.net (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)'
'domain' => domain,
}
}
end
it 'prints output with host fqdn, template, duration info, and tags' do
output = "- #{fqdn} (redhat-7-x86_64, 7.67/48 hours, user: bob, role: agent)"
expect(STDOUT).to receive(:puts).with(output)
service = Service.new(MockOptions.new, 'url' => url)
allow(service).to receive(:query)
.with(nil, hostname)
.and_return(response_body)
Utils.pretty_print_hosts(nil, service, hostname)
subject
end
end
it 'prints a nonstandard pooler output with host, template, and time remaining' do
hostname = 'sol11-9.delivery.mycompany.net'
response_body = { hostname => {
context 'when print_to_stderr option is true' do
let(:print_to_stderr) { true }
it 'outputs to stderr instead of stdout' do
expect(STDERR).to receive(:puts).with(default_output)
subject
end
end
end
describe 'with nonstandard pooler service' do
let(:service) { Service.new(MockOptions.new, 'url' => url, 'type' => 'ns') }
let(:hostname) { 'sol11-9.delivery.mycompany.net' }
let(:response_body) do
{
hostname => {
'fqdn' => hostname,
'os_triple' => 'solaris-11-sparc',
'reserved_by_user' => 'first.last',
'reserved_for_reason' => '',
'hours_left_on_reservation' => 35.89,
} }
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining)'
expect(STDOUT).to receive(:puts).with(output)
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
allow(service).to receive(:query)
.with(nil, hostname)
.and_return(response_body)
Utils.pretty_print_hosts(nil, service, hostname)
}
}
end
it 'prints a nonstandard pooler output with host, template, time remaining, and reason' do
hostname = 'sol11-9.delivery.mycompany.net'
response_body = { hostname => {
let(:default_output) { "- #{hostname} (solaris-11-sparc, 35.89h remaining)" }
it 'prints output with host, template, and time remaining' do
expect(STDOUT).to receive(:puts).with(default_output)
subject
end
context 'when reason is supplied' do
let(:response_body) do
{
hostname => {
'fqdn' => hostname,
'os_triple' => 'solaris-11-sparc',
'reserved_by_user' => 'first.last',
'reserved_for_reason' => 'testing',
'hours_left_on_reservation' => 35.89,
} }
}
}
end
it 'prints output with host, template, time remaining, and reason' do
output = '- sol11-9.delivery.mycompany.net (solaris-11-sparc, 35.89h remaining, reason: testing)'
expect(STDOUT).to receive(:puts).with(output)
service = Service.new(MockOptions.new, 'url' => url, 'type' => 'ns')
allow(service).to receive(:query)
.with(nil, hostname)
.and_return(response_body)
subject
end
end
Utils.pretty_print_hosts(nil, service, hostname)
context 'when print_to_stderr option is true' do
let(:print_to_stderr) { true }
it 'outputs to stderr instead of stdout' do
expect(STDERR).to receive(:puts).with(default_output)
subject
end
end
end
describe 'with ABS service' do
let(:service) { Service.new(MockOptions.new, 'url' => url, 'type' => 'abs') }
let(:hostname) { '1597952189390' }
let(:fqdn) { 'example-noun.delivery.puppetlabs.net' }
let(:template) { 'ubuntu-1604-x86_64' }
# This seems to be the miminal stub response from ABS for the current output
let(:response_body) do
{
hostname => {
'state' => 'allocated',
'allocated_resources' => [
{
'hostname' => fqdn,
'type' => template,
'engine' => 'vmpooler',
},
],
'request' => {
'job' => {
'id' => hostname,
}
},
}
}
end
let(:default_output) { "- [JobID:#{hostname}] #{fqdn} (#{template}) <allocated>" }
before(:each) do
allow(Utils).to receive(:get_vmpooler_service_config).and_return({
'url' => 'http://vmpooler.example.com',
'token' => 'krypto-knight'
})
end
it 'prints output with job id, host, and template' do
expect(STDOUT).to receive(:puts).with(default_output)
subject
end
context 'when print_to_stderr option is true' do
let(:print_to_stderr) { true }
it 'outputs to stderr instead of stdout' do
expect(STDERR).to receive(:puts).with(default_output)
subject
end
end
end
end