1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #598 from nate/feature/unmocking

Feature/unmocking
This commit is contained in:
Wesley Beary 2011-11-09 11:40:39 -08:00
commit efcef8972b
3 changed files with 92 additions and 3 deletions

View file

@ -65,7 +65,7 @@ After that you should be able to check your directory list in fog or your filesy
## Next Steps
Using the same interface you can also practice working against a real provider (such as Amazon S3). Rather than worrying about signing up for an account right away though, we can use mocks to simulate S3 while we practice.
Using the same interface you can also practice working against a real provider (such as Amazon S3). Rather than worrying about signing up for an account right away though, we can use mocks to simulate S3 while we practice.
This time we will turn on mocking and then, just like before, we will need to make a connection.
@ -76,8 +76,33 @@ This time we will turn on mocking and then, just like before, we will need to ma
:provider => 'AWS'
})
You may notice that we used bogus credentials, this is fine since we are just simulating things. To use real S3 you can simply omit `Fog.mock!` and swap in your real credentials.
You may notice that we used bogus credentials, this is fine since we are just simulating things. To use real S3 you can simply omit Fog.mock! and swap in your real credentials.
Once you have your connection you can go through all the steps you did before, only now you will be working against a real cloud service (or at least a simulated one).
If you'd like to turn off mocking after turning it on, you can do it at any time and every subsequent connection will be a real connection.
# Turn on mocking
Fog.mock!
# Create a mock connection to S3
storage = Fog::Storage.new({
:aws_access_key_id => "asdf",
:aws_secret_access_key => "asdf",
:provider => "AWS"
})
# Turn off mocking
Fog.unmock!
# Create a real connection to S3
storage = Fog::Storage.new({
:aws_access_key_id => "asdf",
:aws_secret_access_key => "asdf",
:provider => "AWS"
})
Don't worry about your losing mock data, it stays around until you reset it or until your process exits.
# Reset all mock data
Fog::Mock.reset
Congratulations and welcome to the cloud! Continue your journey at [fog.io](http://fog.io)

View file

@ -6,6 +6,10 @@ module Fog
@mocking = true
end
def self.unmock!
@mocking = false
end
def self.mock?
@mocking
end

View file

@ -0,0 +1,60 @@
Shindo.tests('Fog mocking', 'core') do
before do
@fog_was_mocked = Fog.mock?
Fog.unmock! if @fog_was_mocked
end
after do
Fog.mock! if @fog_was_mocked
end
tests('Fog.mock!') do
tests('Fog.mock!').returns(true) do
Fog.mock!
end
tests('Fog.mock? without Fog.mock!').returns(false) do
Fog.mock?
end
tests('Fog.mock? with Fog.mock!').returns(true) do
Fog.mock!
Fog.mock?
end
tests('Fog.mocking? without Fog.mock!').returns(false) do
Fog.mocking?
end
tests('Fog.mocking? with Fog.mock!').returns(true) do
Fog.mock!
Fog.mocking?
end
end
tests('Fog::Mock.delay') do
tests('Fog::Mock.delay').returns(1, "defaults to 1") do
Fog::Mock.delay
end
tests('Fog::Mock.delay = 2').returns(2, "changes Fog::Mock.delay to 2") do
Fog::Mock.delay = 2
Fog::Mock.delay
end
tests('Fog::Mock.delay = 0').returns(0, "changes Fog::Mock.delay to 0") do
Fog::Mock.delay = 0
Fog::Mock.delay
end
tests('Fog::Mock.delay = -1').raises(ArgumentError) do
Fog::Mock.delay = -1
end
end
tests('Fog::Mock.not_implemented').raises(Fog::Errors::MockNotImplemented) do
Fog::Mock.not_implemented
end
end