Skip to content

Commit 9fe5300

Browse files
committed
[API] Test Runner: Refactors logging
1 parent 12ab22b commit 9fe5300

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'logger'
19+
20+
module Elasticsearch
21+
module RestAPIYAMLTests
22+
module Logging
23+
def self.logger
24+
@logger ||= Logger.new($stdout)
25+
end
26+
end
27+
end
28+
end

elasticsearch-api/api-spec-testing/test_file.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
require_relative 'test_file/action'
1919
require_relative 'test_file/test'
2020
require_relative 'test_file/task_group'
21-
require 'logger'
21+
require_relative 'logging'
2222

2323
module Elasticsearch
2424
module RestAPIYAMLTests
@@ -33,8 +33,6 @@ class SkipTestsException < StandardError
3333
class TestFile
3434
attr_reader :features_to_skip, :name, :client
3535

36-
LOGGER = Logger.new($stdout)
37-
3836
# Initialize a single test file.
3937
#
4038
# @example Create a test file object.
@@ -51,8 +49,8 @@ def initialize(file_name, client, features_to_skip = [])
5149
begin
5250
documents = YAML.load_stream(File.new(file_name))
5351
rescue StandardError => e
54-
LOGGER.error e
55-
LOGGER.error "Filename : #{@name}"
52+
Elasticsearch::RestAPIYAMLTests::Logging.logger.error e
53+
Elasticsearch::RestAPIYAMLTests::Logging.logger.error "Filename : #{@name}"
5654
end
5755
@test_definitions = documents.reject { |doc| doc['setup'] || doc['teardown'] }
5856
@setup = documents.find { |doc| doc['setup'] }

elasticsearch-api/api-spec-testing/wipe_cluster.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18+
require_relative 'logging'
19+
1820
module Elasticsearch
1921
module RestAPIYAMLTests
2022
module WipeCluster
@@ -87,7 +89,7 @@ def wait_for_pending_tasks(client)
8789
results.each do |task|
8890
next if task.empty?
8991

90-
LOGGER.debug "Pending task: #{task}"
92+
Elasticsearch::RestAPIYAMLTests::Logging.logger.debug "Pending task: #{task}"
9193
count += 1 if task.include?(filter)
9294
end
9395
break unless count.positive? && Time.now.to_i < (time + 30)
@@ -103,7 +105,7 @@ def wait_for_cluster_tasks(client)
103105
results['tasks'].each do |task|
104106
next if task.empty?
105107

106-
LOGGER.debug "Pending cluster task: #{task}"
108+
Elasticsearch::RestAPIYAMLTests::Logging.logger.debug "Pending cluster task: #{task}"
107109
count += 1
108110
end
109111
break unless count.positive? && Time.now.to_i < (time + 30)
@@ -287,7 +289,7 @@ def wipe_datastreams(client)
287289
begin
288290
client.indices.delete_data_stream(name: '*', expand_wildcards: 'all')
289291
rescue StandardError => e
290-
LOGGER.error "Caught exception attempting to delete data streams: #{e}"
292+
Elasticsearch::RestAPIYAMLTests::Logging.logger.error "Caught exception attempting to delete data streams: #{e}"
291293
client.indices.delete_data_stream(name: '*')
292294
end
293295
end
@@ -302,7 +304,7 @@ def clear_ml_filters(client)
302304
def clear_indices(client)
303305
client.indices.delete(index: '*,-.ds-ilm-history-*', expand_wildcards: 'open,closed,hidden', ignore: 404)
304306
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e
305-
LOGGER.info "Exception trying to delete index #{e}"
307+
Elasticsearch::RestAPIYAMLTests::Logging.logger.info "Exception trying to delete index #{e}"
306308
end
307309

308310
def wipe_searchable_snapshot_indices(client)

0 commit comments

Comments
 (0)