Test service abstraction code loading

The abstraction modules e.g. `Fog::Compute` have a list of registered
providers. All of these providers should be loaded correctly when
accessed with `Fog::Service[:provider]`

These tests hit each endpoint expecting `ArgumentError` from each
provider caused by the lack of credentials.

Credentials are stubbed out to not cause false results when the test
environment does have credentials for a service.

Some services do not have requirements so do not raise the expected
error. These special cases are just asserted. If they are not loaded the
specs fail again.
This commit is contained in:
Paul Thornthwaite 2014-12-18 09:18:27 +00:00
parent d4868d6fde
commit fcd22c9a9a
16 changed files with 230 additions and 3 deletions

View File

@ -46,7 +46,7 @@ Gem::Specification.new do |s|
## List your runtime dependencies here. Runtime dependencies are those
## that are needed for an end user to actually USE your code.
s.add_dependency("fog-core", "~> 1.27", ">= 1.27.1")
s.add_dependency("fog-core", "~> 1.27", ">= 1.27.2")
s.add_dependency("fog-json")
s.add_dependency("fog-xml", "~> 0.1.1")

15
spec/fog/account_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Account do
Fog::Account.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Account[provider] }
end
end
end
end
end

15
spec/fog/billing_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Billing do
Fog::Billing.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Billing[provider] }
end
end
end
end
end

15
spec/fog/cdn_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::CDN do
Fog::CDN.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::CDN[provider] }
end
end
end
end
end

View File

@ -2,7 +2,19 @@ require "minitest/autorun"
require "fog"
describe Fog::Compute do
it "responds to []" do
assert_respond_to Fog::Compute, :[]
Fog::Compute.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
# These providers do not raise ArgumentError since they have no requirements defined
if [:openvz, :vmfusion].include?(provider)
assert Fog::Compute[provider]
else
assert_raises(ArgumentError) { Fog::Compute[provider] }
end
end
end
end
end
end

20
spec/fog/dns_spec.rb Normal file
View File

@ -0,0 +1,20 @@
require "minitest/autorun"
require "fog"
describe Fog::DNS do
Fog::DNS.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
# These providers do not raise ArgumentError since they have no requirements defined
if [:dnsimple].include?(provider)
assert Fog::DNS[provider]
else
assert_raises(ArgumentError) { Fog::DNS[provider] }
end
end
end
end
end
end

15
spec/fog/identity_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Identity do
Fog::Identity.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Identity[provider] }
end
end
end
end
end

15
spec/fog/image_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Image do
Fog::Image.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Image[provider] }
end
end
end
end
end

15
spec/fog/metering_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Metering do
Fog::Metering.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Metering[provider] }
end
end
end
end
end

View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Monitoring do
Fog::Monitoring.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Monitoring[provider] }
end
end
end
end
end

15
spec/fog/network_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Network do
Fog::Network.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Network[provider] }
end
end
end
end
end

View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Orchestration do
Fog::Orchestration.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Orchestration[provider] }
end
end
end
end
end

15
spec/fog/storage_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Storage do
Fog::Storage.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Storage[provider] }
end
end
end
end
end

15
spec/fog/support_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Support do
Fog::Support.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Support[provider] }
end
end
end
end
end

15
spec/fog/volume_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::Volume do
Fog::Volume.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::Volume[provider] }
end
end
end
end
end

15
spec/fog/vpn_spec.rb Normal file
View File

@ -0,0 +1,15 @@
require "minitest/autorun"
require "fog"
describe Fog::VPN do
Fog::VPN.providers.each do |provider|
describe "when #{provider} is passed with no available credentials" do
it "returns ArgumentError" do
# Stub credentials so you still see errors where the tester really has credentials
Fog.stub :credentials, {} do
assert_raises(ArgumentError) { Fog::VPN[provider] }
end
end
end
end
end