Skip to content

Commit

Permalink
Correct get blob properties mock, fixes #387. (#388)
Browse files Browse the repository at this point in the history
Ensure get_blob_properties returns an azure blob instead of a hash
  • Loading branch information
easkay authored and bilal-naeem-confiz committed Jun 13, 2018
1 parent ea87a2a commit 981270c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
52 changes: 26 additions & 26 deletions lib/fog/azurerm/requests/storage/get_blob_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ def get_blob_properties(container_name, name, options = {})
# This class provides the mock implementation for unit tests.
class Mock
def get_blob_properties(*)
{
'name' => 'test_blob',
'metadata' => {},
'properties' => {
'last_modified' => 'Mon, 04 Jul 2016 09:30:31 GMT',
'etag' => '0x8D3A3EDD7C2B777',
'lease_status' => 'unlocked',
'lease_state' => 'available',
'lease_duration' => nil,
'content_length' => 4_194_304,
'content_type' => 'application/octet-stream',
'content_encoding' => nil,
'content_language' => nil,
'content_disposition' => nil,
'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
'cache_control' => nil,
'sequence_number' => 0,
'blob_type' => 'PageBlob',
'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c',
'copy_status' => 'success',
'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z',
'copy_progress' => '4194304/4194304',
'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT',
'copy_status_description' => nil,
'accept_ranges' => 0
}
blob = Azure::Storage::Blob::Blob.new
blob.name = 'test_blob'
blob.metadata = {}
blob.properties = {
last_modified: 'Mon, 04 Jul 2016 09:30:31 GMT',
etag: '0x8D3A3EDD7C2B777',
lease_status: 'unlocked',
lease_state: 'available',
lease_duration: nil,
content_length: 4_194_304,
content_type: 'application/octet-stream',
content_encoding: nil,
content_language: nil,
content_disposition: nil,
content_md5: 'tXAohIyxuu/t94Lp/ujeRw==',
cache_control: nil,
sequence_number: 0,
blob_type: 'PageBlob',
copy_id: '095adc3b-e277-4c3d-97e0-0abca881f60c',
copy_status: 'success',
copy_source: 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z',
copy_progress: '4194304/4194304',
copy_completion_time: 'Thu, 04 Feb 2016 08:35:52 GMT',
copy_status_description: nil,
accept_ranges: 0
}
blob
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/fog/azurerm/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Mock
def initialize(_options = {})
begin
require 'azure_mgmt_storage'
require 'azure/storage'
rescue LoadError => e
retry if require('rubygems')
raise e.message
Expand Down
9 changes: 9 additions & 0 deletions test/api_stub/requests/storage/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ module Storage
# Below data should be as same as those in Mock classes in lib/fog/azurerm/requests/storage/*.rb
class File
def self.blob
blob_data = blob_as_hash
blob = Azure::Storage::Blob::Blob.new
blob.name = blob_data['name']
blob.metadata = blob_data['metadata']
blob.properties = blob_data['properties'].map { |k, v| { k.to_sym => v } }.reduce({}, &:merge!)
blob
end

def self.blob_as_hash
{
'name' => 'test_blob',
'metadata' => {},
Expand Down
2 changes: 1 addition & 1 deletion test/requests/storage/test_get_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup
@blob_client = @service.instance_variable_get(:@blob_client)

@raw_cloud_blob = storage_blob
@blob = ApiStub::Requests::Storage::File.blob
@blob = ApiStub::Requests::Storage::File.blob_as_hash
@blob_with_content = [
@blob,
'content'
Expand Down
4 changes: 3 additions & 1 deletion test/requests/storage/test_get_blob_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def test_get_blob_properties_http_exception
end

def test_get_blob_properties_mock
assert_equal @blob, @mock_service.get_blob_properties('test_container', 'test_blob')
mock_blob_properties = @mock_service.get_blob_properties('test_container', 'test_blob')
assert_equal @blob.name, mock_blob_properties.name
assert_equal @blob.properties, mock_blob_properties.properties
end
end

0 comments on commit 981270c

Please sign in to comment.