-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de7d0fd
commit 4bf7ee9
Showing
10 changed files
with
133 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
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,18 +14,16 @@ | |
@token = 'utpg2i2xswor6h8ttjhu3d47z53yy47y' | ||
end | ||
|
||
it 'returns a token from vmpooler' do | ||
stub_request(:post, 'https://first.last:[email protected]/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' }) | ||
it 'returns a token from abs' do | ||
stub_request(:post, "https://first.last:[email protected]/api/v2/token") | ||
.to_return(:status => 200, :body => @get_token_response, :headers => {}) | ||
|
||
token = Auth.get_token(false, @abs_url, 'first.last', 'password') | ||
expect(token).to eq @token | ||
end | ||
|
||
it 'raises a token error if something goes wrong' do | ||
stub_request(:post, 'https://first.last:[email protected]/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' }) | ||
stub_request(:post, "https://first.last:[email protected]/api/v2/token") | ||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {}) | ||
|
||
expect { Auth.get_token(false, @abs_url, 'first.last', 'password') }.to raise_error(TokenError) | ||
|
@@ -39,16 +37,14 @@ | |
end | ||
|
||
it 'deletes the specified token' do | ||
stub_request(:delete, 'https://first.last:[email protected]/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 => {}) | ||
stub_request(:delete, "https://first.last:[email protected]/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y") | ||
.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) | ||
end | ||
|
||
it 'raises a token error if something goes wrong' do | ||
stub_request(:delete, 'https://first.last:[email protected]/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' }) | ||
stub_request(:delete, "https://first.last:[email protected]/api/v2/token/utpg2i2xswor6h8ttjhu3d47z53yy47y") | ||
.to_return(:status => 500, :body => '{"ok":false}', :headers => {}) | ||
|
||
expect { Auth.delete_token(false, @abs_url, 'first.last', 'password', @token) }.to raise_error(TokenError) | ||
|
@@ -67,15 +63,15 @@ | |
|
||
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) | ||
end | ||
|
||
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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" => Hash.new, | ||
"ubuntu-7.2-x86_64" => Hash.new | ||
} | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.