Commit 6f037848 authored by Mark Chao's avatar Mark Chao

Add spec for Gitlab::Git::Repository#attributes

seed_helper changed because testing requires attributes file in repo,
but repo was not a real git repo but instead faked.
parent d0b746d8
...@@ -94,7 +94,7 @@ describe Gitlab::Git::AttributesParser, :seed_helper do ...@@ -94,7 +94,7 @@ describe Gitlab::Git::AttributesParser, :seed_helper do
# It's a bit hard to test for something _not_ being processed. As such we'll # It's a bit hard to test for something _not_ being processed. As such we'll
# just test the number of entries. # just test the number of entries.
it 'ignores any comments and empty lines' do it 'ignores any comments and empty lines' do
expect(subject.patterns.length).to eq(10) expect(subject.patterns.length).to eq(12)
end end
end end
...@@ -126,7 +126,7 @@ describe Gitlab::Git::AttributesParser, :seed_helper do ...@@ -126,7 +126,7 @@ describe Gitlab::Git::AttributesParser, :seed_helper do
describe '#each_line' do describe '#each_line' do
it 'iterates over every line in the attributes file' do it 'iterates over every line in the attributes file' do
args = [String] * 14 # the number of lines in the file args = [String] * 16 # the number of lines in the file
expect { |b| subject.each_line(&b) }.to yield_successive_args(*args) expect { |b| subject.each_line(&b) }.to yield_successive_args(*args)
end end
......
...@@ -1194,6 +1194,34 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -1194,6 +1194,34 @@ describe Gitlab::Git::Repository, :seed_helper do
end end
end end
describe '#gitattribute' do
let(:repository) { Gitlab::Git::Repository.new('default', TEST_GITATTRIBUTES_REPO_PATH, '') }
after do
ensure_seeds
end
it 'returns matching language attribute' do
expect(repository.gitattribute("custom-highlighting/test.gitlab-custom", 'gitlab-language')).to eq('ruby')
end
it 'returns matching language attribute with additional options' do
expect(repository.gitattribute("custom-highlighting/test.gitlab-cgi", 'gitlab-language')).to eq('erb?parent=json')
end
it 'returns nil if nothing matches' do
expect(repository.gitattribute("report.xslt", 'gitlab-language')).to eq(nil)
end
context 'without gitattributes file' do
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH, '') }
it 'returns nil' do
expect(repository.gitattribute("README.md", 'gitlab-language')).to eq(nil)
end
end
end
describe '#ref_exists?' do describe '#ref_exists?' do
it 'returns true for an existing tag' do it 'returns true for an existing tag' do
expect(repository.ref_exists?('refs/heads/master')).to eq(true) expect(repository.ref_exists?('refs/heads/master')).to eq(true)
......
# frozen_string_literal: true
require_relative 'test_env' require_relative 'test_env'
# This file is specific to specs in spec/lib/gitlab/git/ # This file is specific to specs in spec/lib/gitlab/git/
SEED_STORAGE_PATH = TestEnv.repos_path SEED_STORAGE_PATH = TestEnv.repos_path
TEST_REPO_PATH = 'gitlab-git-test.git'.freeze TEST_REPO_PATH = 'gitlab-git-test.git'
TEST_NORMAL_REPO_PATH = 'not-bare-repo.git'.freeze TEST_NORMAL_REPO_PATH = 'not-bare-repo.git'
TEST_MUTABLE_REPO_PATH = 'mutable-repo.git'.freeze TEST_MUTABLE_REPO_PATH = 'mutable-repo.git'
TEST_BROKEN_REPO_PATH = 'broken-repo.git'.freeze TEST_BROKEN_REPO_PATH = 'broken-repo.git'
TEST_GITATTRIBUTES_REPO_PATH = 'with-git-attributes.git'
module SeedHelper module SeedHelper
GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __dir__).freeze GITLAB_GIT_TEST_REPO_URL = File.expand_path('../gitlab-git-test.git', __dir__)
def ensure_seeds def ensure_seeds
if File.exist?(SEED_STORAGE_PATH) if File.exist?(SEED_STORAGE_PATH)
...@@ -66,6 +69,11 @@ module SeedHelper ...@@ -66,6 +69,11 @@ module SeedHelper
end end
def create_git_attributes def create_git_attributes
system(git_env, *%W(#{Gitlab.config.git.bin_path} clone --bare #{TEST_REPO_PATH} #{TEST_GITATTRIBUTES_REPO_PATH}),
chdir: SEED_STORAGE_PATH,
out: '/dev/null',
err: '/dev/null')
dir = File.join(SEED_STORAGE_PATH, 'with-git-attributes.git', 'info') dir = File.join(SEED_STORAGE_PATH, 'with-git-attributes.git', 'info')
FileUtils.mkdir_p(dir) FileUtils.mkdir_p(dir)
...@@ -82,6 +90,8 @@ foo/bar.* foo ...@@ -82,6 +90,8 @@ foo/bar.* foo
*.cgi key=value?p1=v1&p2=v2 *.cgi key=value?p1=v1&p2=v2
/*.png gitlab-language=png /*.png gitlab-language=png
*.binary binary *.binary binary
/custom-highlighting/*.gitlab-custom gitlab-language=ruby
/custom-highlighting/*.gitlab-cgi gitlab-language=erb?parent=json
# This uses a tab instead of spaces to ensure the parser also supports this. # This uses a tab instead of spaces to ensure the parser also supports this.
*.md\tgitlab-language=markdown *.md\tgitlab-language=markdown
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment