Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_resources_data_processor_spec.rb « tools « spec « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ae43974a0c8d303c90d5404dcbfeeb4409375df (plain)
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
# frozen_string_literal: true

require 'active_support/testing/time_helpers'

RSpec.describe QA::Tools::TestResourceDataProcessor do
  include QA::Support::Helpers::StubEnv
  include ActiveSupport::Testing::TimeHelpers

  subject(:processor) { Class.new(described_class).instance }

  let(:info) { 'information' }
  let(:api_response) { {} }
  let(:method) { :api }
  let(:time) { 2 }
  let(:api_path) { resource.api_delete_path }
  let(:resource) { QA::Resource::Project.init { |project| project.id = 1 } }

  let(:result) do
    {
      'QA::Resource::Project' => [{
        info: info,
        api_path: api_path,
        fabrication_method: method,
        fabrication_time: time,
        http_method: :post,
        timestamp: Time.now.to_s
      }]
    }
  end

  before do
    processor.collect(resource: resource, info: info, fabrication_method: method, fabrication_time: time)
  end

  around do |example|
    freeze_time { example.run }
  end

  describe '.collect' do
    it 'collects and stores resource' do
      expect(processor.resources).to eq(result)
    end
  end

  describe '.write_to_file' do
    using RSpec::Parameterized::TableSyntax

    where(:ci, :suite_failed, :file_path) do
      true  | true  | 'root/tmp/failed-test-resources-random.json'
      true  | false | 'root/tmp/test-resources-random.json'
      false | true  | 'root/tmp/failed-test-resources.json'
      false | false | 'root/tmp/test-resources.json'
    end

    with_them do
      let(:resources_file) { Pathname.new(file_path) }

      before do
        allow(QA::Runtime::Env).to receive(:running_in_ci?).and_return(ci)
        allow(File).to receive(:write)
        allow(QA::Runtime::Path).to receive(:qa_root).and_return('root')
        allow(SecureRandom).to receive(:hex).with(any_args).and_return('random')
      end

      it 'writes applicable resources to file' do
        processor.write_to_file(suite_failed)

        expect(File).to have_received(:write).with(resources_file, JSON.pretty_generate(result))
      end
    end
  end
end