diff options
author | Matthias Kaeppler <mkaeppler@gitlab.com> | 2020-10-26 19:14:51 +0300 |
---|---|---|
committer | Matthias Kaeppler <mkaeppler@gitlab.com> | 2020-10-27 12:56:35 +0300 |
commit | 06fa5a6e950a313bbc3548b70d4d0e6667f65f4c (patch) | |
tree | fac5fa3e1ef65e2b54e34f678b4b044dbf3438a8 | |
parent | 9c1b1dcdc00176881bdeda77b8d1ca0e0c39e074 (diff) |
Set a default log dirmk/set-logdir-default
Since otherwise we default to `/`, which is not writeable.
-rw-r--r-- | ruby/lib/gitlab/config.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/config_spec.rb | 26 |
2 files changed, 25 insertions, 3 deletions
diff --git a/ruby/lib/gitlab/config.rb b/ruby/lib/gitlab/config.rb index 1631315f1..7f25b1446 100644 --- a/ruby/lib/gitlab/config.rb +++ b/ruby/lib/gitlab/config.rb @@ -83,7 +83,7 @@ module Gitlab class Logging def dir - @dir ||= ENV['GITALY_LOG_DIR'] + @dir ||= (ENV['GITALY_LOG_DIR'].presence || Dir.mktmpdir(["gitaly_", "_logs"])) end def level diff --git a/ruby/spec/lib/gitlab/config_spec.rb b/ruby/spec/lib/gitlab/config_spec.rb index 7652ba278..46321f3ea 100644 --- a/ruby/spec/lib/gitlab/config_spec.rb +++ b/ruby/spec/lib/gitlab/config_spec.rb @@ -1,6 +1,28 @@ require 'spec_helper' describe Gitlab::Config do + describe 'Logging' do + subject { described_class::Logging.new } + + describe '#dir' do + context 'when GITALY_LOG_DIR is set' do + it 'uses the setting' do + allow(ENV).to receive(:[]).with('GITALY_LOG_DIR').and_return('/path/to/logs') + + expect(subject.dir).to eq('/path/to/logs') + end + end + + context 'when GITALY_LOG_DIR is blank' do + it 'uses a default directory' do + allow(ENV).to receive(:[]).with('GITALY_LOG_DIR').and_return('') + + expect(subject.dir).not_to eq('') + end + end + end + end + describe '#gitlab_shell' do subject { described_class.new.gitlab_shell } @@ -12,7 +34,7 @@ describe Gitlab::Config do allow(ENV).to receive(:[]).with('GITLAB_SHELL_DIR').and_return(nil) end - it { expect(subject.path).to eq(gitlab_shell_path) } + specify { expect(subject.path).to eq(gitlab_shell_path) } end context 'when GITLAB_SHELL_DIR is set' do @@ -21,7 +43,7 @@ describe Gitlab::Config do allow(ENV).to receive(:[]).with('GITLAB_SHELL_DIR').and_return(gitlab_shell_path) end - it { expect(subject.path).to eq(gitlab_shell_path) } + specify { expect(subject.path).to eq(gitlab_shell_path) } end end end |