diff options
| author | Rémy Coutable <remy@rymai.me> | 2016-09-27 14:29:51 +0000 |
|---|---|---|
| committer | Rémy Coutable <remy@rymai.me> | 2016-09-27 14:29:51 +0000 |
| commit | 0b4fd0af16555b2bdc28f6b18781d72226c5d56c (patch) | |
| tree | c3a252d71cab51e47d4f1a03c40abe0a1851f6f2 /spec | |
| parent | b71ca5da9fde4fa8457af146bd090ec7caa28d60 (diff) | |
| parent | 192e2bd367494bf66746c8971896a2d9cb84fc92 (diff) | |
| download | gitlab-shell-3.6.2.tar.gz | |
Merge branch '59-git-tracing' into 'master'
v3.6.2
Enable GIT_TRACE_PERFORMANCE through a config variable.
The value of the variable must an absolute path needs to exist so we’re able to check if we can write in that file. Because in the
case we cannot write we’ll throw a warning to the output of the users.
```sh
~/dev/gitlab/local/pacoguzman/gitlab-ce (master=)$ git push origin master
warning: could not open '/wadus' for tracing: Permission denied
Everything up-to-date
```
Closes #59
See merge request !91
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/gitlab_shell_spec.rb | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/spec/gitlab_shell_spec.rb b/spec/gitlab_shell_spec.rb index 96cae40..b9b8659 100644 --- a/spec/gitlab_shell_spec.rb +++ b/spec/gitlab_shell_spec.rb @@ -361,7 +361,7 @@ describe GitlabShell do describe :exec_cmd do let(:shell) { GitlabShell.new(key_id) } - before { Kernel.stub!(:exec) } + before { Kernel.stub(:exec) } it "uses Kernel::exec method" do Kernel.should_receive(:exec).with(kind_of(Hash), 1, 2, unsetenv_others: true).once @@ -376,6 +376,72 @@ describe GitlabShell do Kernel.should_receive(:exec).with(kind_of(Hash), [1, 2], unsetenv_others: true).once shell.send :exec_cmd, [1, 2] end + + context "when specifying a git_tracing log file" do + let(:git_trace_log_file) { '/tmp/git_trace_performance.log' } + + before do + GitlabConfig.any_instance.stub(git_trace_log_file: git_trace_log_file) + shell + end + + it "uses GIT_TRACE_PERFORMANCE" do + expected_hash = hash_including( + 'GIT_TRACE' => git_trace_log_file, + 'GIT_TRACE_PACKET' => git_trace_log_file, + 'GIT_TRACE_PERFORMANCE' => git_trace_log_file + ) + Kernel.should_receive(:exec).with(expected_hash, [1, 2], unsetenv_others: true).once + + shell.send :exec_cmd, [1, 2] + end + + context "when provides a relative path" do + let(:git_trace_log_file) { 'git_trace_performance.log' } + + it "does not uses GIT_TRACE*" do + # If we try to use it we'll show a warning to the users + expected_hash = hash_excluding( + 'GIT_TRACE', 'GIT_TRACE_PACKET', 'GIT_TRACE_PERFORMANCE' + ) + Kernel.should_receive(:exec).with(expected_hash, [1, 2], unsetenv_others: true).once + + shell.send :exec_cmd, [1, 2] + end + + it "writes an entry on the log" do + expect($logger).to receive(:warn). + with("gitlab-shell: is configured to trace git commands with #{git_trace_log_file.inspect} but an absolute path needs to be provided") + + Kernel.should_receive(:exec).with(kind_of(Hash), [1, 2], unsetenv_others: true).once + shell.send :exec_cmd, [1, 2] + end + end + + context "when provides a file not writable" do + before do + expect(File).to receive(:open).with(git_trace_log_file, 'a').and_raise(Errno::EACCES) + end + + it "does not uses GIT_TRACE*" do + # If we try to use it we'll show a warning to the users + expected_hash = hash_excluding( + 'GIT_TRACE', 'GIT_TRACE_PACKET', 'GIT_TRACE_PERFORMANCE' + ) + Kernel.should_receive(:exec).with(expected_hash, [1, 2], unsetenv_others: true).once + + shell.send :exec_cmd, [1, 2] + end + + it "writes an entry on the log" do + expect($logger).to receive(:warn). + with("gitlab-shell: is configured to trace git commands with #{git_trace_log_file.inspect} but it's not possible to write in that path Permission denied") + + Kernel.should_receive(:exec).with(kind_of(Hash), [1, 2], unsetenv_others: true).once + shell.send :exec_cmd, [1, 2] + end + end + end end describe :api do |
