debian-mirror-gitlab/spec/lib/gitlab/file_detector_spec.rb

103 lines
3.3 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe Gitlab::FileDetector do
describe '.types_in_paths' do
it 'returns the file types for the given paths' do
2017-09-10 17:25:29 +05:30
expect(described_class.types_in_paths(%w(README.md CHANGELOG VERSION VERSION)))
.to eq(%i{readme changelog version})
2017-08-17 22:00:37 +05:30
end
it 'does not include unrecognized file paths' do
2017-09-10 17:25:29 +05:30
expect(described_class.types_in_paths(%w(README.md foo.txt)))
.to eq(%i{readme})
2017-08-17 22:00:37 +05:30
end
end
describe '.type_of' do
it 'returns the type of a README file' do
2018-12-13 13:39:08 +05:30
filenames = Gitlab::MarkupHelper::PLAIN_FILENAMES + Gitlab::MarkupHelper::PLAIN_FILENAMES.map(&:upcase)
extensions = Gitlab::MarkupHelper::EXTENSIONS + Gitlab::MarkupHelper::EXTENSIONS.map(&:upcase)
filenames.each do |filename|
expect(described_class.type_of(filename)).to eq(:readme)
extensions.each do |extname|
expect(described_class.type_of("#{filename}.#{extname}")).to eq(:readme)
end
end
end
it 'returns nil for a README.rb file' do
expect(described_class.type_of('README.rb')).to be_nil
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'returns nil for a README file in a directory' do
expect(described_class.type_of('foo/README.md')).to be_nil
end
2017-08-17 22:00:37 +05:30
it 'returns the type of a changelog file' do
%w(CHANGELOG HISTORY CHANGES NEWS).each do |file|
expect(described_class.type_of(file)).to eq(:changelog)
end
end
it 'returns the type of a license file' do
2018-11-20 20:47:30 +05:30
%w(LICENSE LICENCE COPYING UNLICENSE UNLICENCE).each do |file|
2017-08-17 22:00:37 +05:30
expect(described_class.type_of(file)).to eq(:license)
end
end
2018-11-20 20:47:30 +05:30
it 'returns nil for an UNCOPYING file' do
expect(described_class.type_of('UNCOPYING')).to be_nil
end
2017-08-17 22:00:37 +05:30
it 'returns the type of a version file' do
expect(described_class.type_of('VERSION')).to eq(:version)
end
it 'returns the type of a .gitignore file' do
expect(described_class.type_of('.gitignore')).to eq(:gitignore)
end
it 'returns the type of a GitLab CI config file' do
expect(described_class.type_of('.gitlab-ci.yml')).to eq(:gitlab_ci)
end
it 'returns the type of an avatar' do
%w(logo.gif logo.png logo.jpg).each do |file|
expect(described_class.type_of(file)).to eq(:avatar)
end
end
2018-03-17 18:26:18 +05:30
it 'returns the type of an issue template' do
expect(described_class.type_of('.gitlab/issue_templates/foo.md')).to eq(:issue_template)
end
it 'returns the type of a merge request template' do
expect(described_class.type_of('.gitlab/merge_request_templates/foo.md')).to eq(:merge_request_template)
end
2017-08-17 22:00:37 +05:30
it 'returns nil for an unknown file' do
expect(described_class.type_of('foo.txt')).to be_nil
end
2020-01-01 13:55:28 +05:30
it 'returns the type of an OpenAPI spec if file name is correct' do
openapi_types = [
'openapi.yml', 'openapi.yaml', 'openapi.json',
'swagger.yml', 'swagger.yaml', 'swagger.json',
'gitlab_swagger.yml', 'openapi_gitlab.yml',
'OpenAPI.YML', 'openapi.Yaml', 'openapi.JSON',
'openapi.gitlab.yml', 'gitlab.openapi.yml'
]
openapi_types.each do |type_name|
expect(described_class.type_of(type_name)).to eq(:openapi)
end
expect(described_class.type_of('openapiyml')).to be_nil
end
2017-08-17 22:00:37 +05:30
end
end