mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(#33) Handle Auth class errors
This commit updates the Auth class to properly raise an error when something goes wrong. It also updates the vmpooler command class to handle when those errors get raised.
This commit is contained in:
parent
05e9d5a0cc
commit
8da1deaf6b
4 changed files with 85 additions and 45 deletions
|
|
@ -20,6 +20,14 @@ describe Pooler do
|
|||
token = Auth.get_token(false, @vmpooler_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:password@vmpooler.example.com/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, @vmpooler_url, "first.last", "password") }.to raise_error(TokenError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#delete_token" do
|
||||
|
|
@ -35,6 +43,14 @@ describe Pooler do
|
|||
|
||||
expect(Auth.delete_token(false, @vmpooler_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:password@vmpooler.example.com/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, @vmpooler_url, "first.last", "password", @token) }.to raise_error(TokenError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#token_status" do
|
||||
|
|
@ -50,5 +66,13 @@ describe Pooler do
|
|||
|
||||
expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response)
|
||||
end
|
||||
|
||||
it "raises a token error if something goes wrong" do
|
||||
stub_request(:get, "#{@vmpooler_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'}).
|
||||
to_return(:status => 500, :body => "{\"ok\":false}", :headers => {})
|
||||
|
||||
expect{ Auth.token_status(false, @vmpooler_url, @token) }.to raise_error(TokenError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue