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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'qa/spec/tools/test_resources_data_processor_spec.rb')
-rw-r--r--qa/spec/tools/test_resources_data_processor_spec.rb63
1 files changed, 45 insertions, 18 deletions
diff --git a/qa/spec/tools/test_resources_data_processor_spec.rb b/qa/spec/tools/test_resources_data_processor_spec.rb
index 6a8c0fd06a4..5117d1d367f 100644
--- a/qa/spec/tools/test_resources_data_processor_spec.rb
+++ b/qa/spec/tools/test_resources_data_processor_spec.rb
@@ -1,33 +1,60 @@
# 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_path) { '/foo' }
- let(:result) { [{ info: info, api_path: api_path }] }
+ 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 } }
- describe '.collect' do
- context 'when resource is not restricted' do
- let(:resource) { instance_double(QA::Resource::Project, api_delete_path: '/foo', api_response: 'foo') }
+ 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
- it 'collects resource' do
- expect(described_class.collect(resource, info)).to eq(result)
- end
+ describe '.collect' do
+ it 'collects and stores resource' do
+ expect(processor.resources).to eq(result)
end
+ end
+
+ describe '.write_to_file' do
+ let(:resources_file) { Pathname.new(Faker::File.file_name(dir: 'tmp', ext: 'json')) }
- context 'when resource api response is nil' do
- let(:resource) { double(QA::Resource::Project, api_delete_path: '/foo', api_response: nil) }
+ before do
+ stub_env('QA_TEST_RESOURCES_CREATED_FILEPATH', resources_file)
- it 'does not collect resource' do
- expect(described_class.collect(resource, info)).to eq(nil)
- end
+ allow(File).to receive(:write)
end
- context 'when resource is restricted' do
- let(:resource) { double(QA::Resource::Sandbox, api_delete_path: '/foo', api_response: 'foo') }
+ it 'writes applicable resources to file' do
+ processor.write_to_file
- it 'does not collect resource' do
- expect(described_class.collect(resource, info)).to eq(nil)
- end
+ expect(File).to have_received(:write).with(resources_file, JSON.pretty_generate(result))
end
end
end