17417: Merge branch 'main' into 17417-add-arm64
[arvados.git] / services / api / test / integration / logging_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'stringio'
6
7 class LoggingTest < ActionDispatch::IntegrationTest
8   fixtures :collections
9
10   test "request_id" do
11     buf = StringIO.new
12     logcopy = ActiveSupport::Logger.new(buf)
13     logcopy.level = :info
14     begin
15       Rails.logger.extend(ActiveSupport::Logger.broadcast(logcopy))
16       get "/arvados/v1/collections/#{collections(:foo_file).uuid}",
17           params: {:format => :json},
18           headers: auth(:active).merge({ 'X-Request-Id' => 'req-aaaaaaaaaaaaaaaaaaaa' })
19       assert_response :success
20       assert_match /^{.*"request_id":"req-aaaaaaaaaaaaaaaaaaaa"/, buf.string
21     ensure
22       # We don't seem to have an "unbroadcast" option, so this is how
23       # we avoid filling buf with unlimited logs from subsequent
24       # tests.
25       logcopy.level = :fatal
26     end
27   end
28 end