mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
better mocked values
This commit is contained in:
parent
4d327641d9
commit
019979a908
2 changed files with 45 additions and 1 deletions
|
@ -24,5 +24,49 @@ module Fog
|
|||
Fog::AWS::S3.reload
|
||||
end
|
||||
|
||||
if Fog.mocking?
|
||||
srand(Time.now.to_i)
|
||||
|
||||
class Mock
|
||||
|
||||
def self.letters(length)
|
||||
random_selection(
|
||||
'abcdefghijklmnopqrstuvwxyz',
|
||||
length
|
||||
)
|
||||
end
|
||||
|
||||
def self.numbers(length)
|
||||
random_selection(
|
||||
'0123456789',
|
||||
length
|
||||
)
|
||||
end
|
||||
|
||||
def self.hex(length)
|
||||
random_selection(
|
||||
'0123456789abcdef',
|
||||
length
|
||||
)
|
||||
end
|
||||
|
||||
def self.etag
|
||||
hex(32)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.random_selection(characters, length)
|
||||
selection = ''
|
||||
length.times do
|
||||
position = rand(characters.length)
|
||||
selection << characters[position..position]
|
||||
end
|
||||
selection
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,7 +56,7 @@ else
|
|||
bucket = @data['Buckets'].select {|bucket| bucket['Name'] == bucket_name}.first
|
||||
bucket['Contents'] << {
|
||||
:body => file[:body],
|
||||
'ETag' => Digest::SHA1.hexdigest(rand.to_s)[0...32],
|
||||
'ETag' => Fog::AWS::Mock.etag,
|
||||
'Key' => object_name,
|
||||
'LastModified' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000"),
|
||||
'Owner' => { 'DisplayName' => 'owner', 'ID' => 'some_id'},
|
||||
|
|
Loading…
Reference in a new issue