rev_list_spec.rb 1.97 KB
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe Gitlab::Git::RevList, lib: true do
  let(:project) { create(:project) }

  context "validations" do
7 8 9 10 11
    described_class::ALLOWED_VARIABLES.each do |var|
      context var do
        it "accepts values starting with the project repo path" do
          env = { var => "#{project.repository.path_to_repo}/objects" }
          rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)
12

13 14
          expect(rev_list).to be_valid
        end
15

16 17 18
        it "rejects values starting not with the project repo path" do
          env = { var => "/some/other/path" }
          rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)
19

20 21
          expect(rev_list).not_to be_valid
        end
22

23 24 25
        it "rejects values containing the project repo path but not starting with it" do
          env = { var => "/some/other/path/#{project.repository.path_to_repo}" }
          rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)
26

27 28
          expect(rev_list).not_to be_valid
        end
29 30 31 32 33 34 35

        it "ignores nil values" do
          env = { var => nil }
          rev_list = described_class.new('oldrev', 'newrev', project: project, env: env)

          expect(rev_list).to be_valid
        end
36 37
      end
    end
38 39 40 41 42 43 44 45 46
  end

  context "#execute" do
    let(:env) { { "GIT_OBJECT_DIRECTORY" => project.repository.path_to_repo } }
    let(:rev_list) { Gitlab::Git::RevList.new('oldrev', 'newrev', project: project, env: env) }

    it "calls out to `popen` without environment variables if the record is invalid" do
      allow(rev_list).to receive(:valid?).and_return(false)

47
      expect(Open3).to receive(:popen3).with(hash_excluding(env), any_args)
48

49
      rev_list.execute
50 51 52 53 54
    end

    it "calls out to `popen` with environment variables if the record is valid" do
      allow(rev_list).to receive(:valid?).and_return(true)

55
      expect(Open3).to receive(:popen3).with(hash_including(env), any_args)
56

57
      rev_list.execute
58 59 60
    end
  end
end