Class: Fog::Storage::AzureRM::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/azurerm/storage.rb,
lib/fog/azurerm/requests/storage/copy_blob.rb,
lib/fog/azurerm/requests/storage/list_blobs.rb,
lib/fog/azurerm/requests/storage/delete_blob.rb,
lib/fog/azurerm/requests/storage/delete_disk.rb,
lib/fog/azurerm/requests/storage/compare_blob.rb,
lib/fog/azurerm/requests/storage/list_containers.rb,
lib/fog/azurerm/requests/storage/check_blob_exist.rb,
lib/fog/azurerm/requests/storage/create_container.rb,
lib/fog/azurerm/requests/storage/delete_container.rb,
lib/fog/azurerm/requests/storage/get_blob_metadata.rb,
lib/fog/azurerm/requests/storage/set_blob_metadata.rb,
lib/fog/azurerm/requests/storage/acquire_blob_lease.rb,
lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb,
lib/fog/azurerm/requests/storage/release_blob_lease.rb,
lib/fog/azurerm/requests/storage/get_blob_properties.rb,
lib/fog/azurerm/requests/storage/get_storage_account.rb,
lib/fog/azurerm/requests/storage/set_blob_properties.rb,
lib/fog/azurerm/requests/storage/download_blob_to_file.rb,
lib/fog/azurerm/requests/storage/list_storage_accounts.rb,
lib/fog/azurerm/requests/storage/create_storage_account.rb,
lib/fog/azurerm/requests/storage/delete_storage_account.rb,
lib/fog/azurerm/requests/storage/get_container_metadata.rb,
lib/fog/azurerm/requests/storage/set_container_metadata.rb,
lib/fog/azurerm/requests/storage/acquire_container_lease.rb,
lib/fog/azurerm/requests/storage/get_storage_access_keys.rb,
lib/fog/azurerm/requests/storage/release_container_lease.rb,
lib/fog/azurerm/requests/storage/get_container_properties.rb,
lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb,
lib/fog/azurerm/requests/storage/upload_block_blob_from_file.rb,
lib/fog/azurerm/requests/storage/get_container_access_control_list.rb,
lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb

Overview

This class provides the mock implementation for unit tests.

Instance Method Summary collapse

Constructor Details

#initialize(_options = {}) ⇒ Mock

Returns a new instance of Mock.



65
66
67
68
69
70
71
72
# File 'lib/fog/azurerm/storage.rb', line 65

def initialize(_options = {})
  begin
    require 'azure_mgmt_storage'
  rescue LoadError => e
    retry if require('rubygems')
    raise e.message
  end
end

Instance Method Details

#acquire_blob_leaseObject



21
22
23
24
25
# File 'lib/fog/azurerm/requests/storage/acquire_blob_lease.rb', line 21

def acquire_blob_lease(*)
  {
    'leaseId' => 'abc123'
  }
end

#acquire_container_leaseObject



21
22
23
24
25
# File 'lib/fog/azurerm/requests/storage/acquire_container_lease.rb', line 21

def acquire_container_lease(*)
  {
    'leaseId' => 'abc123'
  }
end

#check_blob_existObject



19
20
21
# File 'lib/fog/azurerm/requests/storage/check_blob_exist.rb', line 19

def check_blob_exist(*)
  true
end

#check_storage_account_name_availability(params) ⇒ Object



26
27
28
29
# File 'lib/fog/azurerm/requests/storage/check_storage_account_name_availability.rb', line 26

def (params)
  Fog::Logger.debug "Name: #{params.name} is available."
  true
end

#compare_blobObject



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
# File 'lib/fog/azurerm/requests/storage/compare_blob.rb', line 39

def compare_blob(*)
  [
    {
      'name' => 'blob_name',
      'metadata' => {},
      'properties' =>
        {
          'last_modified' => 'Thu, 28 Jul 2016 06:53:05 GMT',
          'etag' => '0x8D3B6B3D353FFCA',
          'lease_status' => 'unlocked',
          'lease_state' => 'available',
          'lease_duration' => nil,
          'content_length' => 4_194_304,
          'content_type' => 'application/atom+xml; charset=utf-8',
          'content_encoding' => 'ASCII-8BIT',
          'content_language' => nil,
          'content_disposition' => nil,
          'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
          'cache_control' => nil,
          'blob_type' => 'BlockBlob',
          'copy_id' => nil,
          'copy_status' => nil,
          'copy_source' => nil,
          'copy_progress' => nil,
          'copy_completion_time' => nil,
          'copy_status_description' => nil,
          'accept_ranges' => 0
        }
    }
  ]
end

#copy_blobObject



21
22
23
24
25
26
# File 'lib/fog/azurerm/requests/storage/copy_blob.rb', line 21

def copy_blob(*)
  {
    'copyId' => 'abc123',
    'copyStatus' => 'pending'
  }
end

#copy_blob_from_uriObject



21
22
23
24
25
26
# File 'lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb', line 21

def copy_blob_from_uri(*)
  {
    'copyId' => 'abc123',
    'copyStatus' => 'pending'
  }
end

#create_containerObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/azurerm/requests/storage/create_container.rb', line 21

def create_container(*)
  {
    'name' => 'testcontainer1',
    'properties' =>
      {
        'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
        'etag' => '0x8D3A3B5F017F52D',
        'lease_status' => 'unlocked',
        'lease_state' => 'available'
      },
    'public_access_level' => nil,
    'metadata' => {}
  }
end

#create_storage_accountObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/azurerm/requests/storage/create_storage_account.rb', line 37

def (*)
   = {
    'id' => '/subscriptions/67f2116d-4ea2-4c6c-b20a-f92183dbe3cb/resourceGroups/fog_test_rg/providers/Microsoft.Storage/storageAccounts/fogtestsasecond',
    'name' => 'fog-test-storage-account',
    'location' => 'west us',
    'sku' =>
      {
        'name' => 'Standard_LRS'
      }
  }
   = Azure::ARM::Storage::Models::StorageAccount.mapper
  storage_mgmt_client.deserialize(, , 'hash')
end

#delete_blobObject



20
21
22
23
# File 'lib/fog/azurerm/requests/storage/delete_blob.rb', line 20

def delete_blob(*)
  Fog::Logger.debug 'Blob deleted successfully.'
  true
end

#delete_containerObject



21
22
23
# File 'lib/fog/azurerm/requests/storage/delete_container.rb', line 21

def delete_container(*)
  true
end

#delete_disk(_resource_group, _storage_account_name, blob_name) ⇒ Object



29
30
31
32
33
# File 'lib/fog/azurerm/requests/storage/delete_disk.rb', line 29

def delete_disk(_resource_group, , blob_name)
  Fog::Logger.debug "Deleting Disk: #{blob_name}."
  Fog::Logger.debug "Successfully deleted Disk: #{blob_name}."
  true
end

#delete_storage_account(resource_group, name) ⇒ Object



20
21
22
23
# File 'lib/fog/azurerm/requests/storage/delete_storage_account.rb', line 20

def (resource_group, name)
  Fog::Logger.debug "Storage Account #{name} from Resource group #{resource_group} deleted successfully."
  true
end

#download_blob_to_file(_container_name, blob_name, _file_path, _options = {}) ⇒ Object



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
# File 'lib/fog/azurerm/requests/storage/download_blob_to_file.rb', line 23

def download_blob_to_file(_container_name, blob_name, _file_path, _options = {})
  Fog::Logger.debug 'File downloaded successfully.'
  {
    'name' => blob_name,
    'metadata' => {},
    'properties' =>
      {
        'last_modified' => 'Thu, 28 Jul 2016 06:53:05 GMT',
        'etag' => '0x8D3B6B3D353FFCA',
        'lease_status' => 'unlocked',
        'lease_state' => 'available',
        'lease_duration' => nil,
        'content_length' => 4_194_304,
        'content_type' => 'application/atom+xml; charset=utf-8',
        'content_encoding' => 'ASCII-8BIT',
        'content_language' => nil,
        'content_disposition' => nil,
        'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==',
        'cache_control' => nil,
        'blob_type' => 'BlockBlob',
        'copy_id' => nil,
        'copy_status' => nil,
        'copy_source' => nil,
        'copy_progress' => nil,
        'copy_completion_time' => nil,
        'copy_status_description' => nil,
        'accept_ranges' => 0
      }
  }
end

#get_blob_metadata(container_name, name, _options = {}) ⇒ Object



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
# File 'lib/fog/azurerm/requests/storage/get_blob_metadata.rb', line 20

def (container_name, name, _options = {})
  {
    'name' => name,
    'snapshot' => nil,
    'metadata' => {
      'container-name' => container_name,
      'blob-name' => name,
      'category' => 'Images',
      'resolution' => 'High'
    },
    '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
      }
  }
end

#get_blob_properties(_container_name, name, _options = {}) ⇒ Object



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
# File 'lib/fog/azurerm/requests/storage/get_blob_properties.rb', line 19

def get_blob_properties(_container_name, name, _options = {})
  {
    'name' => name,
    'snapshot' => nil,
    '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
      }
  }
end

#get_container_access_control_listObject



21
22
23
24
25
26
# File 'lib/fog/azurerm/requests/storage/get_container_access_control_list.rb', line 21

def get_container_access_control_list(*)
  [{
    'name' => 'testcontainer1',
    'public_access_level' => 'blob'
  }, {}]
end

#get_container_metadataObject



20
21
22
23
24
25
26
27
28
# File 'lib/fog/azurerm/requests/storage/get_container_metadata.rb', line 20

def (*)
  {
    'container-name' => 'testcontainer1',
    'created-by' => 'User',
    'source-machine' => 'Test-machine',
    'category' => 'guidance',
    'doctype' => 'textDocuments'
  }
end

#get_container_propertiesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/azurerm/requests/storage/get_container_properties.rb', line 21

def get_container_properties(*)
  {
    'name' => 'testcontainer1',
    'properties' =>
      {
        'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
        'etag' => '0x8D3A3B5F017F52D',
        'lease_status' => 'unlocked',
        'lease_state' => 'available'
      },
    'metadata' => {}
  }
end

#get_storage_access_keys(_resource_group, storage_account_name, _options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/fog/azurerm/requests/storage/get_storage_access_keys.rb', line 20

def get_storage_access_keys(_resource_group, , _options = {})
  Fog::Logger.debug "Getting storage access keys for storage account: #{}."
  Fog::Logger.debug "Storage access keys for storage account: #{} listed successfully."
  {
    'key1' => 'key1 value',
    'key2' => 'key2 value'
  }
end

#get_storage_accountObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/azurerm/requests/storage/get_storage_account.rb', line 20

def (*)
   = {
    'id' => '/subscriptions/67f2116d-4ea2-4c6c-b20a-f92183dbe3cb/resourceGroups/fog_test_rg/providers/Microsoft.Storage/storageAccounts/fogtestsasecond',
    'name' => 'fog-test-storage-account',
    'location' => 'west us',
    'sku' =>
        {
          'name' => 'Standard_LRS'
        }
  }
   = Azure::ARM::Storage::Models::StorageAccount.mapper
  storage_mgmt_client.deserialize(, , 'hash')
end

#list_blobsObject



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
# File 'lib/fog/azurerm/requests/storage/list_blobs.rb', line 20

def list_blobs(*)
  Fog::Logger.debug 'Listing blobs in container successfully.'
  [
    {
      'name' => 'testblob1',
      'properties' =>
        {
          'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
          'etag' => '0x8D3A3B5F017F52D',
          'lease_status' => 'unlocked',
          'lease_state' => 'available',
          '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/testblob1?snapshot=2016-02-04T08%3A35%3A50.3256874Z',
          'copy_progress' => '4194304/4194304',
          'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT',
          'copy_status_description' => nil,
          'accept_ranges' => 0
        },
      'metadata' => {}
    },
    {
      'name' => 'testblob2',
      'properties' =>
        {
          'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT',
          'etag' => '0x8D29C92173526C8',
          'lease_status' => 'unlocked',
          'lease_state' => 'available',
          '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' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c',
          'copy_status' => 'success',
          'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/testblob2?snapshot=2016-02-04T08%3A35%3A55.3157696Z',
          'copy_progress' => '4194304/4194304',
          'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT',
          'copy_status_description' => nil,
          'accept_ranges' => 0
        },
      'metadata' => {}
    }
  ]
end

#list_containersObject



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
# File 'lib/fog/azurerm/requests/storage/list_containers.rb', line 21

def list_containers(*)
  [
    {
      'name' => 'testcontainer1',
      'properties' =>
        {
          'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT',
          'etag' => '0x8D3A3B5F017F52D',
          'lease_status' => 'unlocked',
          'lease_state' => 'available'
        },
      'metadata' => {}
    },
    {
      'name' => 'testcontainer2',
      'properties' =>
        {
          'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT',
          'etag' => '0x8D29C92176C8352',
          'lease_status' => 'unlocked',
          'lease_state' => 'available'
        },
      'metadata' => {}
    }
  ]
end

#list_storage_account_for_rg(resource_group) ⇒ Object



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
# File 'lib/fog/azurerm/requests/storage/list_storage_account_for_rg.rb', line 19

def (resource_group)
  [
    {
      'id' => "/subscriptions/{subscriptionId}/resourceGroups/#{resource_group}/providers/Microsoft.Storage/storageAccounts/mock_test_storage_account",
      'name' => 'mock_test_storage_account',
      'type' => 'Microsoft.Storage/storageAccounts',
      'location' => 'westus',
      'tags' => {},
      'properties' =>
      {
        'provisioningState' => 'Succeeded',
        'accountType' => 'Standard_LRS',
        'primaryEndpoints' =>
          {
            'blob' => 'https://mock_test_storage_account.blob.core.windows.net/',
            'queue' => 'https://mock_test_storage_account.queue.core.windows.net/',
            'table' => 'https://mock_test_storage_account.table.core.windows.net/',
            'file' => 'https://mock_test_storage_account.file.core.windows.net/'
          },
        'primaryLocation' => 'westus',
        'statusOfPrimary' => 'available',
        'lastGeoFailoverTime' => '2016-05-19T09:58:55Z',
        'creationTime' => '2016-05-19T05:24:36Z'
      }
    }
  ]
end

#list_storage_accountsObject



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
# File 'lib/fog/azurerm/requests/storage/list_storage_accounts.rb', line 19

def list_storage_accounts
  [
    {
      'id' => '/subscriptions/{subscriptionId}/resourceGroups/mock_test_resource_group/providers/Microsoft.Storage/storageAccounts/mock_test_storage_account',
      'name' => 'mock_test_storage_account',
      'type' => 'Microsoft.Storage/storageAccounts',
      'location' => 'westus',
      'tags' => {},
      'properties' =>
      {
        'provisioningState' => 'Succeeded',
        'accountType' => 'Standard_LRS',
        'primaryEndpoints' =>
        {
          'blob' => 'https://mock_test_storage_account.blob.core.windows.net/',
          'queue' => 'https://mock_test_storage_account.queue.core.windows.net/',
          'table' => 'https://mock_test_storage_account.table.core.windows.net/',
          'file' => 'https://mock_test_storage_account.file.core.windows.net/'
        },
        'primaryLocation' => 'westus',
        'statusOfPrimary' => 'available',
        'lastGeoFailoverTime' => '2016-05-19T09:49:07Z',
        'creationTime' => '2016-05-19T05:24:36Z'
      }
    }
  ]
end

#release_blob_leaseObject



21
22
23
# File 'lib/fog/azurerm/requests/storage/release_blob_lease.rb', line 21

def release_blob_lease(*)
  true
end

#release_container_leaseObject



21
22
23
# File 'lib/fog/azurerm/requests/storage/release_container_lease.rb', line 21

def release_container_lease(*)
  true
end

#set_blob_metadata(container_name, name, metadata, _options = {}) ⇒ Object



20
21
22
23
# File 'lib/fog/azurerm/requests/storage/set_blob_metadata.rb', line 20

def (container_name, name, , _options = {})
  Fog::Logger.debug "Set Blob #{name} metadata #{} in a container #{container_name} successfully."
  true
end

#set_blob_properties(container_name, name, properties = {}) ⇒ Object



19
20
21
22
# File 'lib/fog/azurerm/requests/storage/set_blob_properties.rb', line 19

def set_blob_properties(container_name, name, properties = {})
  Fog::Logger.debug "Set Blob #{name} properties #{properties.inspect} in a container #{container_name} successfully."
  true
end

#set_container_metadataObject



20
21
22
23
# File 'lib/fog/azurerm/requests/storage/set_container_metadata.rb', line 20

def (*)
  Fog::Logger.debug 'Set Container testcontainer1 metadata successfully.'
  true
end

#upload_block_blob_from_file(_container_name, blob_name, _file_path, _options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/azurerm/requests/storage/upload_block_blob_from_file.rb', line 45

def upload_block_blob_from_file(_container_name, blob_name, _file_path, _options = {})
  Fog::Logger.debug 'Blob created successfully.'
  {
    'name' => blob_name,
    'properties' =>
      {
        'last_modified' => 'Thu, 28 Jul 2016 06:53:05 GMT',
        'etag' => '0x8D3B6B3D353FFCA',
        'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw=='
      }
  }
end