1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
add_filter 'test'
command_name 'Minitest'
end
end
if ENV['CODECLIMATE_REPO_TOKEN']
require 'simplecov'
SimpleCov.start do
add_filter 'test'
command_name 'Minitest'
end
end
class TestRaiseLogger
def write(message)
raise message
end
def tty?
false
end
end
require 'fog/core/logger'
Fog::Logger[:deprecation] = TestRaiseLogger.new
Fog::Logger[:warning] = TestRaiseLogger.new
require 'minitest/autorun'
require 'azure/core/http/http_error'
require 'azure/core/http/http_response'
$LOAD_PATH.unshift(File.expand_path '../lib', __dir__)
require 'fog/azurerm'
require File.expand_path './api_stub', __dir__
def storage_account_credentials
{
azure_storage_account_name: 'mockaccount',
azure_storage_access_key: 'YWNjZXNzLWtleQ=='
}
end
def storage_account_credentials_with_endpoint
storage_account_credentials.merge(
{
azure_storage_endpoint: 'http://localhost:10000/mockaccount'
}
)
end
def storage_account_credentials_with_domain
storage_account_credentials.merge(
{
azure_storage_domain: 'test.example.com'
}
)
end
def storage_account_credentials_with_token_signer
{
azure_storage_account_name: 'mockaccount',
azure_storage_token_signer: mock_token_signer
}
end
def mock_token_signer
@mock_token_signer ||= Minitest::Mock.new(Azure::Core::Auth::Signer.new('access-token'))
end
# Mock Class for Blob
class MockBlob
def initialize
@properties = {}
@metadata = {}
yield self if block_given?
end
attr_accessor :name
attr_accessor :snapshot
attr_accessor :properties
attr_accessor :metadata
end
# Mock Class for Response
class MockResponse
def initialize(code, body, headers)
@status = code
@body = body
@headers = headers
@headers.each do |k, v|
@headers[k] = [v] unless v.respond_to? 'first'
end
end
attr_accessor :status
attr_accessor :body
attr_accessor :headers
end
def mocked_storage_http_error
mocked_net_response = MockResponse.new 'mocked_code', 'mocked_body', a: 'a', b: 'b'
Azure::Core::Http::HttpResponse.new mocked_net_response, 'mocked_uri'
end
def mocked_storage_http_not_found_error
mocked_net_response = MockResponse.new '404', 'mocked_body', a: 'a', b: 'b'
Azure::Core::Http::HttpResponse.new mocked_net_response, 'mocked_uri'
end
def directory(service)
Fog::AzureRM::Storage::Directory.new(
key: 'test_container',
acl: 'container',
etag: '0x8D29C92176C8352',
last_modified: Time.parse('Tue, 04 Aug 2015 06:01:08 GMT'),
lease_duration: nil,
lease_state: 'available',
lease_status: 'unlocked',
metadata: {
'key1' => 'value1',
'key2' => 'value2'
},
service: service,
collection: Fog::AzureRM::Storage::Directories.new(service: @service)
)
end
def file(service)
Fog::AzureRM::Storage::File.new(
key: 'test_blob',
directory: directory(service),
last_modified: Time.parse('Tue, 04 Aug 2015 06:01:08 GMT'),
etag: '0x8D29C92176C8352',
metadata: {
'key1' => 'value1',
'key2' => 'value2'
},
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: 'BlockBlob',
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,
service: service,
collection: Fog::AzureRM::Storage::Files.new(service: @service, directory: directory(service))
)
end
def storage_blob
mock_blob = MockBlob.new
mock_blob.name = 'test_blob'
mock_blob.properties = {
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://mockaccount.blob.core.windows.net/test_container/test_blob?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,
last_modified: 'Tue, 04 Aug 2015 06:01:08 GMT',
etag: '"0x8D29C92176C8352"'
}
mock_blob.metadata = {
'key1' => 'value1',
'key2' => 'value2'
}
mock_blob
end
|