File: test_list_blobs.rb

package info (click to toggle)
ruby-gitlab-fog-azure-rm 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 756 kB
  • sloc: ruby: 5,926; sh: 9; makefile: 4
file content (77 lines) | stat: -rw-r--r-- 2,516 bytes parent folder | download | duplicates (2)
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
require File.expand_path '../../test_helper', __dir__

# Storage Blob Class
class TestListBlobs < Minitest::Test
  # This class posesses the test cases for the requests of listing blobs in storage containers.
  def setup
    Fog.mock!
    @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials)
    Fog.unmock!
    @mocked_response = mocked_storage_http_error

    @service = Fog::AzureRM::Storage.new(storage_account_credentials)
    @blob_client = @service.instance_variable_get(:@blob_client)

    @blob_list = ApiStub::Requests::Storage::File.blob_list
    @blobs1 = Azure::Storage::Common::Service::EnumerationResults.new
    @blobs1.continuation_token = 'marker'
    @blobs1.push(@blob_list[0])
    @blobs1.push(@blob_list[1])
    @blobs2 = Azure::Storage::Common::Service::EnumerationResults.new
    @blobs2.push(@blob_list[2])
    @blobs2.push(@blob_list[3])
  end

  def test_list_blobs_success
    multiple_values = lambda do |_container_name, options|
      return @blobs2 if options[:marker] == 'marker'
      return @blobs1
    end
    @blob_client.stub :list_blobs, multiple_values do
      result = @service.list_blobs('test_container')
      assert result[:next_marker].nil?
      assert_equal @blob_list, result[:blobs]
    end
  end

  def test_list_blobs_with_max_results_success
    @blob_client.stub :list_blobs, @blobs1 do
      options = { max_results: 2 }
      result = @service.list_blobs('test_container', options)
      assert_equal 'marker', result[:next_marker]
      assert_equal @blob_list[0, 2], result[:blobs]
    end
  end

  def test_list_blobs_not_found
    exception = ->(*) { raise StandardError.new('Not found(404). Not exist') }
    @blob_client.stub :list_blobs, exception do
      assert_raises('NotFound') do
        @service.list_blobs('test_container')
      end
    end
  end

  def test_list_blobs_http_exception
    http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) }
    @blob_client.stub :list_blobs, http_exception do
      assert_raises(Azure::Core::Http::HTTPError) do
        @service.list_blobs('test_container')
      end
    end
  end

  def test_list_blobs_exception
    @blob_client.stub :list_blobs, 'exception' do
      assert_raises(RuntimeError) do
        @service.list_blobs('test_container')
      end
    end
  end

  def test_list_blobs_mock
    result = @mock_service.list_blobs('test_container')
    assert_equal 'marker', result[:next_marker]
    assert_equal @blob_list, result[:blobs]
  end
end