mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-25 21:28:40 -05:00
Rebasing fixed tests
This commit is contained in:
parent
de7d0fdeab
commit
a77ea84092
11 changed files with 217 additions and 111 deletions
|
|
@ -5,7 +5,7 @@ require_relative '../../../lib/vmfloaty/auth'
|
|||
|
||||
describe Pooler do
|
||||
before :each do
|
||||
@abs_url = 'https://abs.example.com'
|
||||
@abs_url = 'https://abs.example.com/api/v2'
|
||||
end
|
||||
|
||||
describe '#get_token' do
|
||||
|
|
@ -14,9 +14,8 @@ describe Pooler do
|
|||
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y'
|
||||
end
|
||||
|
||||
it 'returns a token from vmpooler' do
|
||||
it 'returns a token from abs' do
|
||||
stub_request(:post, 'https://first.last:password@abs.example.com/api/v2/token')
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' })
|
||||
.to_return(:status => 200, :body => @get_token_response, :headers => {})
|
||||
|
||||
token = Auth.get_token(false, @abs_url, 'first.last', 'password')
|
||||
|
|
@ -25,7 +24,6 @@ describe Pooler do
|
|||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:post, 'https://first.last:password@abs.example.com/api/v2/token')
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Length' => '0', 'User-Agent' => 'Faraday v0.9.2' })
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
|
||||
expect { Auth.get_token(false, @abs_url, 'first.last', 'password') }.to raise_error(TokenError)
|
||||
|
|
@ -40,7 +38,6 @@ describe Pooler do
|
|||
|
||||
it 'deletes the specified token' do
|
||||
stub_request(:delete, 'https://first.last:password@abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' })
|
||||
.to_return(:status => 200, :body => @delete_token_response, :headers => {})
|
||||
|
||||
expect(Auth.delete_token(false, @abs_url, 'first.last', 'password', @token)).to eq JSON.parse(@delete_token_response)
|
||||
|
|
@ -48,7 +45,6 @@ describe Pooler do
|
|||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:delete, 'https://first.last:password@abs.example.com/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y')
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' })
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
|
||||
expect { Auth.delete_token(false, @abs_url, 'first.last', 'password', @token) }.to raise_error(TokenError)
|
||||
|
|
@ -67,7 +63,7 @@ describe Pooler do
|
|||
|
||||
it 'checks the status of a token' do
|
||||
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' })
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
|
||||
.to_return(:status => 200, :body => @token_status_response, :headers => {})
|
||||
|
||||
expect(Auth.token_status(false, @abs_url, @token)).to eq JSON.parse(@token_status_response)
|
||||
|
|
@ -75,7 +71,7 @@ describe Pooler do
|
|||
|
||||
it 'raises a token error if something goes wrong' do
|
||||
stub_request(:get, "#{@abs_url}/token/utpg2i2xswor6h8ttjhu3d47z53yy47y")
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent' => 'Faraday v0.9.2' })
|
||||
.with(:headers => { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3' })
|
||||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {})
|
||||
|
||||
expect { Auth.token_status(false, @abs_url, @token) }.to raise_error(TokenError)
|
||||
|
|
|
|||
38
spec/vmfloaty/abs_spec.rb
Normal file
38
spec/vmfloaty/abs_spec.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
require 'vmfloaty/utils'
|
||||
require 'vmfloaty/errors'
|
||||
require 'vmfloaty/abs'
|
||||
|
||||
describe ABS do
|
||||
before :each do
|
||||
end
|
||||
|
||||
describe '#format' do
|
||||
it 'returns an hash formatted like a vmpooler return' do
|
||||
abs_formatted_response = [
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaab.delivery.puppetlabs.net', 'type' => 'centos-7.2-x86_64', 'engine' => 'vmpooler' },
|
||||
{ 'hostname' => 'aaaaaaaaaaaaaac.delivery.puppetlabs.net', 'type' => 'ubuntu-7.2-x86_64', 'engine' => 'vmpooler' },
|
||||
]
|
||||
|
||||
vmpooler_formatted_response = ABS.translated(abs_formatted_response)
|
||||
|
||||
vmpooler_formatted_compare = {
|
||||
'centos-7.2-x86_64' => {},
|
||||
'ubuntu-7.2-x86_64' => {},
|
||||
}
|
||||
|
||||
vmpooler_formatted_compare['centos-7.2-x86_64']['hostname'] = ['aaaaaaaaaaaaaaa.delivery.puppetlabs.net', 'aaaaaaaaaaaaaab.delivery.puppetlabs.net']
|
||||
vmpooler_formatted_compare['ubuntu-7.2-x86_64']['hostname'] = ['aaaaaaaaaaaaaac.delivery.puppetlabs.net']
|
||||
|
||||
vmpooler_formatted_compare['ok'] = true
|
||||
|
||||
expect(vmpooler_formatted_response).to eq(vmpooler_formatted_compare)
|
||||
vmpooler_formatted_response.delete('ok')
|
||||
vmpooler_formatted_compare.delete('ok')
|
||||
expect(vmpooler_formatted_response).to eq(vmpooler_formatted_compare)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -66,7 +66,7 @@ describe NonstandardPooler do
|
|||
@token_status_body_active = <<~BODY
|
||||
{
|
||||
"ok": true,
|
||||
"user": "first.last",
|
||||
"user": 'first.last',
|
||||
"created": "2017-09-18 01:25:41 +0000",
|
||||
"last_accessed": "2017-09-21 19:46:25 +0000",
|
||||
"reserved_hosts": ["sol10-9", "sol10-11"]
|
||||
|
|
@ -75,7 +75,7 @@ describe NonstandardPooler do
|
|||
@token_status_body_empty = <<~BODY
|
||||
{
|
||||
"ok": true,
|
||||
"user": "first.last",
|
||||
"user": 'first.last',
|
||||
"created": "2017-09-18 01:25:41 +0000",
|
||||
"last_accessed": "2017-09-21 19:46:25 +0000",
|
||||
"reserved_hosts": []
|
||||
|
|
@ -125,7 +125,7 @@ describe NonstandardPooler do
|
|||
.to_return(:status => 401, :body => '{"ok":false,"reason": "token: token-value does not exist"}', :headers => {})
|
||||
|
||||
vm_hash = { 'solaris-11-sparc' => 1 }
|
||||
expect { NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url) }.to raise_error(AuthError)
|
||||
expect { NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last') }.to raise_error(AuthError)
|
||||
end
|
||||
|
||||
it 'retrieves a single vm with a token' do
|
||||
|
|
@ -134,7 +134,7 @@ describe NonstandardPooler do
|
|||
.to_return(:status => 200, :body => @retrieve_response_body_single, :headers => {})
|
||||
|
||||
vm_hash = { 'solaris-11-sparc' => 1 }
|
||||
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url)
|
||||
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last')
|
||||
expect(vm_req).to be_an_instance_of Hash
|
||||
expect(vm_req['ok']).to equal true
|
||||
expect(vm_req['solaris-11-sparc']['hostname']).to eq 'sol11-4.delivery.puppetlabs.net'
|
||||
|
|
@ -146,7 +146,7 @@ describe NonstandardPooler do
|
|||
.to_return(:status => 200, :body => @retrieve_response_body_many, :headers => {})
|
||||
|
||||
vm_hash = { 'aix-7.1-power' => 1, 'solaris-10-sparc' => 2 }
|
||||
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url)
|
||||
vm_req = NonstandardPooler.retrieve(false, vm_hash, 'token-value', @nspooler_url, 'first.last')
|
||||
expect(vm_req).to be_an_instance_of Hash
|
||||
expect(vm_req['ok']).to equal true
|
||||
expect(vm_req['solaris-10-sparc']['hostname']).to be_an_instance_of Array
|
||||
|
|
@ -246,7 +246,7 @@ describe NonstandardPooler do
|
|||
"sol10-11": {
|
||||
"fqdn": "sol10-11.delivery.puppetlabs.net",
|
||||
"os_triple": "solaris-10-sparc",
|
||||
"reserved_by_user": "first.last",
|
||||
"reserved_by_user": 'first.last',
|
||||
"reserved_for_reason": "testing",
|
||||
"hours_left_on_reservation": 29.12
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ describe Service do
|
|||
it 'prompts the user for their password and retrieves a token' do
|
||||
config = { 'user' => 'first.last', 'url' => 'http://default.url' }
|
||||
service = Service.new(MockOptions.new, config)
|
||||
allow(STDOUT).to receive(:puts).with('Enter your pooler service password:')
|
||||
allow(STDOUT).to receive(:puts).with('Enter your http://default.url service password:')
|
||||
allow(Commander::UI).to(receive(:password)
|
||||
.with('Enter your pooler service password:', '*')
|
||||
.with('Enter your http://default.url service password:', '*')
|
||||
.and_return('hunter2'))
|
||||
allow(Auth).to(receive(:get_token)
|
||||
.with(nil, config['url'], config['user'], 'hunter2')
|
||||
|
|
@ -29,11 +29,11 @@ describe Service do
|
|||
it 'prompts the user for their username and password if the username is unknown' do
|
||||
config = { 'url' => 'http://default.url' }
|
||||
service = Service.new(MockOptions.new({}), config)
|
||||
allow(STDOUT).to receive(:puts).with 'Enter your pooler service username:'
|
||||
allow(STDOUT).to receive(:puts).with 'Enter your http://default.url service username:'
|
||||
allow(STDOUT).to receive(:puts).with "\n"
|
||||
allow(STDIN).to receive(:gets).and_return('first.last')
|
||||
allow(Commander::UI).to(receive(:password)
|
||||
.with('Enter your pooler service password:', '*')
|
||||
.with('Enter your http://default.url service password:', '*')
|
||||
.and_return('hunter2'))
|
||||
allow(Auth).to(receive(:get_token)
|
||||
.with(nil, config['url'], 'first.last', 'hunter2')
|
||||
|
|
@ -46,7 +46,7 @@ describe Service do
|
|||
it 'deletes a token' do
|
||||
service = Service.new(MockOptions.new, 'user' => 'first.last', 'url' => 'http://default.url')
|
||||
allow(Commander::UI).to(receive(:password)
|
||||
.with('Enter your pooler service password:', '*')
|
||||
.with('Enter your http://default.url service password:', '*')
|
||||
.and_return('hunter2'))
|
||||
allow(Auth).to(receive(:delete_token)
|
||||
.with(nil, 'http://default.url', 'first.last', 'hunter2', 'token-value')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue