|
361 | 361 |
|
362 | 362 | describe :exec_cmd do |
363 | 363 | let(:shell) { GitlabShell.new(key_id) } |
364 | | - before { Kernel.stub!(:exec) } |
| 364 | + before { Kernel.stub(:exec) } |
365 | 365 |
|
366 | 366 | it "uses Kernel::exec method" do |
367 | 367 | Kernel.should_receive(:exec).with(kind_of(Hash), 1, 2, unsetenv_others: true).once |
|
376 | 376 | Kernel.should_receive(:exec).with(kind_of(Hash), [1, 2], unsetenv_others: true).once |
377 | 377 | shell.send :exec_cmd, [1, 2] |
378 | 378 | end |
| 379 | + |
| 380 | + context "when specifying a git_tracing log file" do |
| 381 | + let(:git_trace_log_file) { '/tmp/git_trace_performance.log' } |
| 382 | + |
| 383 | + before do |
| 384 | + GitlabConfig.any_instance.stub(git_trace_log_file: git_trace_log_file) |
| 385 | + shell |
| 386 | + end |
| 387 | + |
| 388 | + it "uses GIT_TRACE_PERFORMANCE" do |
| 389 | + expected_hash = hash_including( |
| 390 | + 'GIT_TRACE' => git_trace_log_file, |
| 391 | + 'GIT_TRACE_PACKET' => git_trace_log_file, |
| 392 | + 'GIT_TRACE_PERFORMANCE' => git_trace_log_file |
| 393 | + ) |
| 394 | + Kernel.should_receive(:exec).with(expected_hash, [1, 2], unsetenv_others: true).once |
| 395 | + |
| 396 | + shell.send :exec_cmd, [1, 2] |
| 397 | + end |
| 398 | + |
| 399 | + context "when provides a relative path" do |
| 400 | + let(:git_trace_log_file) { 'git_trace_performance.log' } |
| 401 | + |
| 402 | + it "does not uses GIT_TRACE*" do |
| 403 | + # If we try to use it we'll show a warning to the users |
| 404 | + expected_hash = hash_excluding( |
| 405 | + 'GIT_TRACE', 'GIT_TRACE_PACKET', 'GIT_TRACE_PERFORMANCE' |
| 406 | + ) |
| 407 | + Kernel.should_receive(:exec).with(expected_hash, [1, 2], unsetenv_others: true).once |
| 408 | + |
| 409 | + shell.send :exec_cmd, [1, 2] |
| 410 | + end |
| 411 | + |
| 412 | + it "writes an entry on the log" do |
| 413 | + expect($logger).to receive(:warn). |
| 414 | + with("gitlab-shell: is configured to trace git commands with #{git_trace_log_file.inspect} but an absolute path needs to be provided") |
| 415 | + |
| 416 | + Kernel.should_receive(:exec).with(kind_of(Hash), [1, 2], unsetenv_others: true).once |
| 417 | + shell.send :exec_cmd, [1, 2] |
| 418 | + end |
| 419 | + end |
| 420 | + |
| 421 | + context "when provides a file not writable" do |
| 422 | + before do |
| 423 | + expect(File).to receive(:open).with(git_trace_log_file, 'a').and_raise(Errno::EACCES) |
| 424 | + end |
| 425 | + |
| 426 | + it "does not uses GIT_TRACE*" do |
| 427 | + # If we try to use it we'll show a warning to the users |
| 428 | + expected_hash = hash_excluding( |
| 429 | + 'GIT_TRACE', 'GIT_TRACE_PACKET', 'GIT_TRACE_PERFORMANCE' |
| 430 | + ) |
| 431 | + Kernel.should_receive(:exec).with(expected_hash, [1, 2], unsetenv_others: true).once |
| 432 | + |
| 433 | + shell.send :exec_cmd, [1, 2] |
| 434 | + end |
| 435 | + |
| 436 | + it "writes an entry on the log" do |
| 437 | + expect($logger).to receive(:warn). |
| 438 | + 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") |
| 439 | + |
| 440 | + Kernel.should_receive(:exec).with(kind_of(Hash), [1, 2], unsetenv_others: true).once |
| 441 | + shell.send :exec_cmd, [1, 2] |
| 442 | + end |
| 443 | + end |
| 444 | + end |
379 | 445 | end |
380 | 446 |
|
381 | 447 | describe :api do |
|
0 commit comments