diff --git a/app/models/fluent_gem.rb b/app/models/fluent_gem.rb index b48b5a5..8622962 100644 --- a/app/models/fluent_gem.rb +++ b/app/models/fluent_gem.rb @@ -17,9 +17,12 @@ module FluentGem # but long living caching causes mismatch with actual status e.g. user install plugin from console (without fluentd-ui) # So our decision is that cache `gem list` in 3 seconds Rails.cache.fetch(LIST_CACHE_KEY, expires_in: 3.seconds) do - output = `#{gem} list` - if $? && $?.exitstatus != 0 # NOTE: $? will be nil on CircleCI, so check $? at first - raise GemError, "failed command: `#{gem} list`" + last_status = $? + output = `#{gem} list 2>&1` + # https://github.com/fluent/fluentd-ui/pull/149#issuecomment-71954588 + # Sometimes, $? wouldn't override with `#{gem} list` but I don't know why.. + if $? && last_status != $? && $?.exitstatus != 0 # NOTE: $? will be nil on CircleCI, so check $? at first + raise GemError, "failed command: `#{gem} list` output: #{output}" end output.lines.to_a end diff --git a/lib/fluentd-ui.rb b/lib/fluentd-ui.rb index 2810851..c3772b5 100644 --- a/lib/fluentd-ui.rb +++ b/lib/fluentd-ui.rb @@ -21,7 +21,11 @@ module FluentdUI end def self.data_dir - dir = ENV["FLUENTD_UI_DATA_DIR"].presence || ENV["HOME"] + "/.fluentd-ui/core_data" + if Rails.env.test? + dir = Rails.root.join("tmp", "core_data").to_s + else + dir = ENV["FLUENTD_UI_DATA_DIR"].presence || ENV["HOME"] + "/.fluentd-ui/core_data" + end FileUtils.mkdir_p(dir) # ensure directory exists dir end diff --git a/spec/models/fluentd/agent/local_common_spec.rb b/spec/models/fluentd/agent/local_common_spec.rb index 8a46cc2..700b1a0 100644 --- a/spec/models/fluentd/agent/local_common_spec.rb +++ b/spec/models/fluentd/agent/local_common_spec.rb @@ -47,6 +47,8 @@ describe 'Fluentd::Agent::LocalCommon' do CONF before do + # other specs could be write in this dir, so clean that in `before` + FileUtils.rm_r daemon.agent.config_backup_dir, force: true ::Settings.max_backup_files_count.times do |i| backuped_time = now - (i + 1).hours FileUtils.touch File.join(daemon.agent.config_backup_dir , "#{backuped_time.strftime('%Y%m%d_%H%M%S')}.conf") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c6dee40..d315e94 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -61,4 +61,8 @@ RSpec.configure do |config| # rspec 2.99 config.infer_spec_type_from_file_location! + + config.after(:suite) do + FileUtils.rm_rf FluentdUI.data_dir + end end