2010-12-16 14:24:52 -05:00
|
|
|
module Fog
|
|
|
|
|
|
|
|
@mocking = false
|
|
|
|
|
|
|
|
def self.mock!
|
|
|
|
@mocking = true
|
|
|
|
end
|
|
|
|
|
2011-11-09 14:30:33 -05:00
|
|
|
def self.unmock!
|
|
|
|
@mocking = false
|
|
|
|
end
|
|
|
|
|
2010-12-16 14:24:52 -05:00
|
|
|
def self.mock?
|
|
|
|
@mocking
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.mocking?
|
|
|
|
@mocking
|
|
|
|
end
|
|
|
|
|
|
|
|
module Mock
|
2011-01-04 14:35:58 -05:00
|
|
|
|
2010-12-16 14:24:52 -05:00
|
|
|
@delay = 1
|
|
|
|
def self.delay
|
|
|
|
@delay
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.delay=(new_delay)
|
|
|
|
raise ArgumentError, "delay must be non-negative" unless new_delay >= 0
|
|
|
|
@delay = new_delay
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.not_implemented
|
|
|
|
raise Fog::Errors::MockNotImplemented.new("Contributions welcome!")
|
|
|
|
end
|
|
|
|
|
2011-01-04 14:35:58 -05:00
|
|
|
def self.random_base64(length)
|
|
|
|
random_selection(
|
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
|
|
length
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.random_hex(length)
|
|
|
|
max = ('f' * length).to_i(16)
|
|
|
|
rand(max).to_s(16).rjust(length, '0')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.random_letters(length)
|
|
|
|
random_selection(
|
|
|
|
'abcdefghijklmnopqrstuvwxyz',
|
|
|
|
length
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.random_numbers(length)
|
|
|
|
max = ('9' * length).to_i
|
|
|
|
rand(max).to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.random_selection(characters, length)
|
|
|
|
selection = ''
|
|
|
|
length.times do
|
|
|
|
position = rand(characters.length)
|
|
|
|
selection << characters[position..position]
|
|
|
|
end
|
|
|
|
selection
|
|
|
|
end
|
|
|
|
|
2011-05-19 10:06:02 -04:00
|
|
|
def self.reset
|
2011-06-21 17:48:21 -04:00
|
|
|
mocked_services = []
|
|
|
|
Fog.constants.map do |x|
|
|
|
|
x_const = Fog.const_get(x)
|
|
|
|
x_const.respond_to?(:constants) && x_const.constants.map do |y|
|
|
|
|
y_const = x_const.const_get(y)
|
|
|
|
y_const.respond_to?(:constants) && y_const.constants.map do |z|
|
|
|
|
if z.to_sym == :Mock
|
|
|
|
mocked_services << y_const.const_get(z)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for mocked_service in mocked_services
|
|
|
|
next unless mocked_service.respond_to?(:reset)
|
|
|
|
mocked_service.reset
|
2011-05-17 22:41:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-16 14:24:52 -05:00
|
|
|
end
|
|
|
|
|
2011-05-19 21:35:37 -04:00
|
|
|
end
|