16470: Fixes tests. Avoids closing a DB connection when using threads on tests.
[arvados.git] / services / api / test / functional / arvados / v1 / healthcheck_controller_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class Arvados::V1::HealthcheckControllerTest < ActionController::TestCase
8   [
9     [false, nil, 404, 'disabled'],
10     [true, nil, 401, 'authorization required'],
11     [true, 'badformatwithnoBearer', 403, 'authorization error'],
12     [true, 'Bearer wrongtoken', 403, 'authorization error'],
13     [true, 'Bearer configuredmanagementtoken', 200, '{"health":"OK"}'],
14   ].each do |enabled, header, error_code, error_msg|
15     test "ping when #{if enabled then 'enabled' else 'disabled' end} with header '#{header}'" do
16       if enabled
17         Rails.configuration.ManagementToken = 'configuredmanagementtoken'
18       else
19         Rails.configuration.ManagementToken = ""
20       end
21
22       @request.headers['Authorization'] = header
23       get :ping
24       assert_response error_code
25
26       resp = JSON.parse(@response.body)
27       if error_code == 200
28         assert_equal(JSON.load('{"health":"OK"}'), resp)
29       else
30         assert_equal(error_msg, resp['errors'])
31       end
32     end
33   end
34 end