Commit 97d7576e authored by Dan Davison's avatar Dan Davison

Merge branch 'acunskis-log-improvements' into 'master'

E2E: Additional logging for resource identifiable attributes

See merge request gitlab-org/gitlab!76086
parents f6e1b8cb 21c1719d
......@@ -80,11 +80,25 @@ module QA
Support::FabricationTracker.start_fabrication
result = yield.tap do
fabrication_time = Time.now - start
resource_identifier = begin
if resource.respond_to?(:username) && resource.username
"with username '#{resource.username}'"
elsif resource.respond_to?(:full_path) && resource.full_path
"with full_path '#{resource.full_path}'"
elsif resource.respond_to?(:name) && resource.name
"with name '#{resource.name}'"
elsif resource.respond_to?(:id) && resource.id
"with id '#{resource.id}'"
end
rescue QA::Resource::Base::NoValueError
nil
end
Support::FabricationTracker.save_fabrication(:"#{method}_fabrication", fabrication_time)
Runtime::Logger.debug do
msg = ["==#{'=' * parents.size}>"]
msg << "Built a #{name}"
msg << resource_identifier if resource_identifier
msg << "as a dependency of #{parents.last}" if parents.any?
msg << "via #{method}"
msg << "in #{fabrication_time} seconds"
......
......@@ -3,8 +3,9 @@
RSpec.describe QA::Resource::Base do
include QA::Support::Helpers::StubEnv
let(:resource) { spy('resource') }
let(:resource) { spy('resource', username: 'qa') }
let(:location) { 'http://location' }
let(:log_regex) { %r{==> Built a MyResource with username 'qa' via #{method} in [\d.\-e]+ seconds+} }
shared_context 'with fabrication context' do
subject do
......@@ -68,6 +69,8 @@ RSpec.describe QA::Resource::Base do
end
context "with debug log level" do
let(:method) { 'api' }
before do
allow(QA::Runtime::Logger).to receive(:debug)
end
......@@ -78,7 +81,7 @@ RSpec.describe QA::Resource::Base do
subject.fabricate_via_api!('something', resource: resource, parents: [])
expect(QA::Runtime::Logger).to have_received(:debug) do |&msg|
expect(msg.call).to match_regex(/==> Built a MyResource via api in [\d.\-e]+ seconds+/)
expect(msg.call).to match_regex(log_regex)
end
end
end
......@@ -102,6 +105,8 @@ RSpec.describe QA::Resource::Base do
end
context "with debug log level" do
let(:method) { 'browser_ui' }
before do
allow(QA::Runtime::Logger).to receive(:debug)
end
......@@ -112,7 +117,7 @@ RSpec.describe QA::Resource::Base do
subject.fabricate_via_browser_ui!('something', resource: resource, parents: [])
expect(QA::Runtime::Logger).to have_received(:debug) do |&msg|
expect(msg.call).to match_regex(/==> Built a MyResource via browser_ui in [\d.\-e]+ seconds+/)
expect(msg.call).to match_regex(log_regex)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment