Skip to content

Commit

Permalink
Pass logger to Configuration class
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Aug 20, 2021
1 parent 12b9a10 commit c85e949
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bin/kafo-export-params
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Kafo

def execute
KafoConfigure.logger = Logger.new(STDERR)
c = Configuration.new(config, false)
c = Configuration.new(config, KafoConfigure.logger, false)
KafoConfigure.config = c
if KafoConfigure.config.parser_cache
KafoConfigure.config.parser_cache.force = true if ARGV.include?('--parser-cache')
Expand Down
4 changes: 2 additions & 2 deletions lib/kafo/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def self.get_scenario_id(filename)
File.basename(filename, '.yaml')
end

def initialize(file, persist = true)
def initialize(file, logger, persist = true)
@config_file = file
@persist = persist
configure_application
@logger = KafoConfigure.logger
@logger = logger

@answer_file = app[:answer_file]
begin
Expand Down
2 changes: 1 addition & 1 deletion lib/kafo/kafo_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def request_config_reload

def setup_config(conf_file)
self.class.config_file = conf_file
self.class.config = Configuration.new(self.class.config_file)
self.class.config = Configuration.new(self.class.config_file, logger)

if self.class.config.parser_cache
self.class.config.parser_cache.force = true if ARGV.include?('--parser-cache')
Expand Down
4 changes: 2 additions & 2 deletions lib/kafo/scenario_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def available_scenarios
content = YAML.load_file(scn_file)
if content.is_a?(Hash) && content.has_key?(:answer_file) && content.fetch(:enabled, true)
# add scenario name for legacy configs
content[:name] = Configuration.get_scenario_id(scn_file) unless content.has_key?(:name)
content[:name] = Configuration.get_scenario_id(scn_file, @logger) unless content.has_key?(:name)
scns[scn_file] = content
end
rescue Psych::SyntaxError => e
Expand Down Expand Up @@ -220,7 +220,7 @@ def load_and_setup_configuration(config_file)
end

def load_configuration(config_file)
Configuration.new(config_file)
Configuration.new(config_file, @logger)
end

private
Expand Down
10 changes: 5 additions & 5 deletions test/kafo/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
module Kafo
describe Configuration do
let(:basic_config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path }
let(:basic_config) { Kafo::Configuration.new(basic_config_file, false) }
let(:old_config) { Kafo::Configuration.new(basic_config_file, false) }
let(:basic_config) { Kafo::Configuration.new(basic_config_file, Kafo::KafoConfigure.logger, false) }
let(:old_config) { Kafo::Configuration.new(basic_config_file, Kafo::KafoConfigure.logger, false) }
let(:current_dir) { File.expand_path('.') }

let(:p_foo) { fake_param('foo', 1) }
Expand Down Expand Up @@ -33,7 +33,7 @@ module Kafo
:answer_file => 'test/fixtures/basic_answers.yaml',
:log_dir => log_dir }
config_file = ConfigFileFactory.build('log_dir', cfg.to_yaml).path
config = Kafo::Configuration.new(config_file, false)
config = Kafo::Configuration.new(config_file, Kafo::KafoConfigure.logger, false)
assert_equal File.join(log_dir, 'configuration.log'), config.log_file
refute config.log_exists?
File.open(config.log_file, 'w') { |f| f.write 'non-empty-log' }
Expand All @@ -51,14 +51,14 @@ module Kafo
it 'takes modules_dir' do
cfg = { :modules_dir => './my_modules', :answer_file => 'test/fixtures/basic_answers.yaml'}
config_file = ConfigFileFactory.build('modules_dir_single', cfg.to_yaml).path
config = Kafo::Configuration.new(config_file, false)
config = Kafo::Configuration.new(config_file, Kafo::KafoConfigure.logger, false)
assert_equal [File.join(current_dir, 'my_modules')], config.module_dirs
end

it 'takes module_dirs' do
cfg = { :module_dirs => ['./my_modules','./their_modules'] , :answer_file => 'test/fixtures/basic_answers.yaml'}
config_file = ConfigFileFactory.build('module_dirs_plural', cfg.to_yaml).path
config = Kafo::Configuration.new(config_file, false)
config = Kafo::Configuration.new(config_file, Kafo::KafoConfigure.logger, false)
assert_equal [File.join(current_dir, 'my_modules'), File.join(current_dir, 'their_modules')], config.module_dirs
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/kafo/execution_environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Kafo
describe ExecutionEnvironment do
let(:config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path }
let(:config) { Kafo::Configuration.new(config_file, false) }
let(:config) { Kafo::Configuration.new(config_file, Kafo::KafoConfigure.logger, false) }
let(:execution_environment) { ExecutionEnvironment.new(config) }

after { FileUtils.rm_rf(execution_environment.directory) }
Expand Down
2 changes: 1 addition & 1 deletion test/kafo/parser_cache_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module Kafo

describe "compatibility with writer" do
before do
KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path)
KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, Kafo::KafoConfigure.logger)
end

let(:parser) { TestParser.new(BASIC_MANIFEST) }
Expand Down
2 changes: 1 addition & 1 deletion test/kafo/puppet_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Kafo
describe PuppetModule do
before do
KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path)
KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, Kafo::KafoConfigure.logger)
end

let(:pc) { PuppetCommand.new '' }
Expand Down
2 changes: 1 addition & 1 deletion test/kafo/puppet_module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Kafo
describe PuppetModule do
before do
KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path)
KafoConfigure.config = Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, Kafo::KafoConfigure.logger)
end

let(:parser) { TestParser.new(BASIC_MANIFEST) }
Expand Down
6 changes: 3 additions & 3 deletions test/kafo/scenario_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def create_and_load_scenarios(content, filename='default.yaml')

describe '#confirm_scenario_change' do
let(:basic_config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path }
let(:new_config) { Kafo::Configuration.new(basic_config_file, false) }
let(:new_config) { Kafo::Configuration.new(basic_config_file, Kafo::KafoConfigure.logger, false) }

before :all do
@argv = ARGV
Expand Down Expand Up @@ -288,8 +288,8 @@ def create_and_load_scenarios(content, filename='default.yaml')

describe '#print_scenario_diff' do
let(:basic_config_file) { ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path }
let(:new_config) { Kafo::Configuration.new(basic_config_file, false) }
let(:old_config) { Kafo::Configuration.new(basic_config_file, false) }
let(:new_config) { Kafo::Configuration.new(basic_config_file, Kafo::KafoConfigure.logger, false) }
let(:old_config) { Kafo::Configuration.new(basic_config_file, Kafo::KafoConfigure.logger, false) }

let(:p_foo) { fake_param('foo', 1) }
let(:p_bar) { fake_param('bar', 10) }
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ class testing4(

class Minitest::Spec
before do
Kafo::KafoConfigure.config = Kafo::Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path)
Kafo::KafoConfigure.logger = Kafo::Logger.new
Kafo::KafoConfigure.config = Kafo::Configuration.new(ConfigFileFactory.build('basic', BASIC_CONFIGURATION).path, Kafo::KafoConfigure.logger)
Kafo::KafoConfigure.root_dir = File.dirname(__FILE__)
Kafo::KafoConfigure.exit_handler = Kafo::ExitHandler.new
Kafo::KafoConfigure.logger = Kafo::Logger.new
Kafo::KafoConfigure.module_dirs = ['test/fixtures/modules']
Kafo::Logging.buffer.clear
end
Expand Down

0 comments on commit c85e949

Please sign in to comment.