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

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/azurerm/storage.rb,
lib/fog/azurerm/requests/storage/delete_disk.rb,
lib/fog/azurerm/requests/storage/list_containers.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/get_storage_account.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/get_storage_access_keys.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/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.



47
48
49
50
51
52
53
54
# File 'lib/fog/azurerm/storage.rb', line 47

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

Instance Method Details

#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

#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_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

#get_blob_metadataObject



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

def (*)
  {
    'container-name' => 'testcontainer1',
    'blob-name' => 'testblob',
    'category' => 'Images',
    'resolution' => 'High'
  }
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_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

#set_blob_metadataObject



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

def (*)
  Fog::Logger.debug "Set Blob metadata in a container 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