From 019979a90822236f97bf759d95a261510c320c4c Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Fri, 14 Aug 2009 09:18:55 -0700 Subject: [PATCH] better mocked values --- lib/fog/aws.rb | 44 +++++++++++++++++++++++++++ lib/fog/aws/requests/s3/put_object.rb | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index 695a6eb52..4228579ae 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -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 diff --git a/lib/fog/aws/requests/s3/put_object.rb b/lib/fog/aws/requests/s3/put_object.rb index cf072919c..6f41107fb 100644 --- a/lib/fog/aws/requests/s3/put_object.rb +++ b/lib/fog/aws/requests/s3/put_object.rb @@ -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'},