2019-11-07 22:06:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-08 10:42:28 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::FileDetector do
|
2016-11-08 10:42:28 -05:00
|
|
|
describe '.types_in_paths' do
|
|
|
|
it 'returns the file types for the given paths' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(described_class.types_in_paths(%w(README.md CHANGELOG VERSION VERSION)))
|
|
|
|
.to eq(%i{readme changelog version})
|
2016-11-08 10:42:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include unrecognized file paths' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(described_class.types_in_paths(%w(README.md foo.txt)))
|
|
|
|
.to eq(%i{readme})
|
2016-11-08 10:42:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.type_of' do
|
2020-01-12 22:07:51 -05:00
|
|
|
it 'returns the type of a README without extension' do
|
|
|
|
expect(described_class.type_of('README')).to eq(:readme)
|
|
|
|
expect(described_class.type_of('INDEX')).to eq(:readme)
|
|
|
|
end
|
2018-11-15 08:06:00 -05:00
|
|
|
|
2020-01-12 22:07:51 -05:00
|
|
|
it 'returns the type of a README file with a recognized extension' do
|
|
|
|
extensions = ['txt', *Gitlab::MarkupHelper::EXTENSIONS]
|
2018-11-15 09:20:58 -05:00
|
|
|
|
2020-01-12 22:07:51 -05:00
|
|
|
extensions.each do |ext|
|
|
|
|
%w(index readme).each do |file|
|
|
|
|
expect(described_class.type_of("#{file}.#{ext}")).to eq(:readme)
|
2018-01-18 08:16:31 -05:00
|
|
|
end
|
|
|
|
end
|
2016-11-08 10:42:28 -05:00
|
|
|
end
|
|
|
|
|
2020-01-12 22:07:51 -05:00
|
|
|
it 'returns nil for a README with unrecognized extension' do
|
2018-11-14 09:37:30 -05:00
|
|
|
expect(described_class.type_of('README.rb')).to be_nil
|
|
|
|
end
|
|
|
|
|
2020-01-12 22:07:51 -05:00
|
|
|
it 'is case insensitive' do
|
|
|
|
expect(described_class.type_of('ReadMe')).to eq(:readme)
|
|
|
|
expect(described_class.type_of('index.TXT')).to eq(:readme)
|
|
|
|
end
|
|
|
|
|
2017-10-11 11:47:03 -04:00
|
|
|
it 'returns nil for a README file in a directory' do
|
|
|
|
expect(described_class.type_of('foo/README.md')).to be_nil
|
|
|
|
end
|
|
|
|
|
2016-11-08 10:42:28 -05:00
|
|
|
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-09-06 08:36:19 -04:00
|
|
|
%w(LICENSE LICENCE COPYING UNLICENSE UNLICENCE).each do |file|
|
2016-11-08 10:42:28 -05:00
|
|
|
expect(described_class.type_of(file)).to eq(:license)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-06 08:36:19 -04:00
|
|
|
it 'returns nil for an UNCOPYING file' do
|
|
|
|
expect(described_class.type_of('UNCOPYING')).to be_nil
|
|
|
|
end
|
|
|
|
|
2016-11-08 10:42:28 -05:00
|
|
|
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
|
|
|
|
|
2017-10-11 11:48:43 -04:00
|
|
|
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
|
|
|
|
|
2016-11-08 10:42:28 -05:00
|
|
|
it 'returns nil for an unknown file' do
|
|
|
|
expect(described_class.type_of('foo.txt')).to be_nil
|
|
|
|
end
|
2019-12-16 07:07:43 -05:00
|
|
|
|
|
|
|
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',
|
2020-03-23 11:09:36 -04:00
|
|
|
'openapi.gitlab.yml', 'gitlab.openapi.yml',
|
|
|
|
'attention/openapi.yml', 'attention/swagger.yml',
|
|
|
|
'attention/gitlab_swagger.yml', 'attention/openapi_gitlab.yml',
|
|
|
|
'openapi/openapi.yml', 'openapi/swagger.yml',
|
|
|
|
'openapi/my_openapi.yml', 'openapi/swagger_one.yml'
|
2019-12-16 07:07:43 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
openapi_types.each do |type_name|
|
|
|
|
expect(described_class.type_of(type_name)).to eq(:openapi)
|
|
|
|
end
|
|
|
|
|
2020-03-23 11:09:36 -04:00
|
|
|
openapi_bad_types = [
|
|
|
|
'openapiyml',
|
|
|
|
'openapi/attention.yaml', 'swagger/attention.yaml'
|
|
|
|
]
|
|
|
|
|
|
|
|
openapi_bad_types.each do |type_name|
|
|
|
|
expect(described_class.type_of(type_name)).to be_nil
|
|
|
|
end
|
2019-12-16 07:07:43 -05:00
|
|
|
end
|
2016-11-08 10:42:28 -05:00
|
|
|
end
|
|
|
|
end
|