diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-03 09:09:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-03 09:09:42 +0000 |
commit | cb48c93abf57768d171e9f8a2f23838a7ce8da07 (patch) | |
tree | 7ff519ac90cce63e3e43139c61fe3b65df73e62e /spec | |
parent | ef9e4ec7a68ace1137f68c19efee470c13631f1d (diff) | |
download | gitlab-ce-cb48c93abf57768d171e9f8a2f23838a7ce8da07.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
5 files changed, 100 insertions, 42 deletions
diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb index 34f81e249e2..0fdd6ab402d 100644 --- a/spec/finders/template_finder_spec.rb +++ b/spec/finders/template_finder_spec.rb @@ -12,7 +12,8 @@ RSpec.describe TemplateFinder do :dockerfiles | described_class :gitignores | described_class :gitlab_ci_ymls | described_class - :licenses | ::LicenseTemplateFinder + :licenses | ::LicenseTemplateFinder + :metrics_dashboard_ymls | described_class end with_them do @@ -28,6 +29,7 @@ RSpec.describe TemplateFinder do :dockerfiles | 'Binary' :gitignores | 'Actionscript' :gitlab_ci_ymls | 'Android' + :metrics_dashboard_ymls | 'Default' end with_them do diff --git a/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb b/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb index 3004de6fe08..55444114d39 100644 --- a/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb +++ b/spec/lib/gitlab/template/gitlab_ci_yml_template_spec.rb @@ -6,10 +6,6 @@ RSpec.describe Gitlab::Template::GitlabCiYmlTemplate do subject { described_class } describe '.all' do - it 'strips the gitlab-ci suffix' do - expect(subject.all.first.name).not_to end_with('.gitlab-ci.yml') - end - it 'combines the globals and rest' do all = subject.all.map(&:name) @@ -17,34 +13,6 @@ RSpec.describe Gitlab::Template::GitlabCiYmlTemplate do expect(all).to include('Docker') expect(all).to include('Ruby') end - - it 'ensure that the template name is used exactly once' do - all = subject.all.group_by(&:name) - duplicates = all.select { |_, templates| templates.length > 1 } - - expect(duplicates).to be_empty - end - end - - describe '.find' do - it 'returns nil if the file does not exist' do - expect(subject.find('mepmep-yadida')).to be nil - end - - it 'returns the GitlabCiYml object of a valid file' do - ruby = subject.find('Ruby') - - expect(ruby).to be_a described_class - expect(ruby.name).to eq('Ruby') - end - end - - describe '.by_category' do - it 'returns sorted results' do - result = described_class.by_category('General') - - expect(result).to eq(result.sort) - end end describe '#content' do @@ -56,13 +24,5 @@ RSpec.describe Gitlab::Template::GitlabCiYmlTemplate do end end - describe '#<=>' do - it 'sorts lexicographically' do - one = described_class.new('a.gitlab-ci.yml') - other = described_class.new('z.gitlab-ci.yml') - - expect(one.<=>(other)).to be(-1) - expect([other, one].sort).to eq([one, other]) - end - end + it_behaves_like 'file template shared examples', 'Ruby', '.gitlab-ci.yml' end diff --git a/spec/lib/gitlab/template/metrics_dashboard_template_spec.rb b/spec/lib/gitlab/template/metrics_dashboard_template_spec.rb new file mode 100644 index 00000000000..4c2b3dea600 --- /dev/null +++ b/spec/lib/gitlab/template/metrics_dashboard_template_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Template::MetricsDashboardTemplate do + subject { described_class } + + describe '.all' do + it 'combines the globals and rest' do + all = subject.all.map(&:name) + + expect(all).to include('Default') + end + end + + describe '#content' do + it 'loads the full file' do + example_dashboard = subject.new(Rails.root.join('lib/gitlab/metrics/templates/Default.metrics-dashboard.yml')) + + expect(example_dashboard.name).to eq 'Default' + expect(example_dashboard.content).to start_with('#') + end + end + + it_behaves_like 'file template shared examples', 'Default', '.metrics-dashboard.yml' +end diff --git a/spec/requests/api/project_templates_spec.rb b/spec/requests/api/project_templates_spec.rb index 59b2b09f0bf..51123837a50 100644 --- a/spec/requests/api/project_templates_spec.rb +++ b/spec/requests/api/project_templates_spec.rb @@ -62,6 +62,15 @@ RSpec.describe API::ProjectTemplates do expect(json_response).to satisfy_one { |template| template['key'] == 'mit' } end + it 'returns metrics_dashboard_ymls' do + get api("/projects/#{public_project.id}/templates/metrics_dashboard_ymls") + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(response).to match_response_schema('public_api/v4/template_list') + expect(json_response).to satisfy_one { |template| template['key'] == 'Default' } + end + it 'returns 400 for an unknown template type' do get api("/projects/#{public_project.id}/templates/unknown") @@ -136,6 +145,14 @@ RSpec.describe API::ProjectTemplates do expect(json_response['name']).to eq('Android') end + it 'returns a specific metrics_dashboard_yml' do + get api("/projects/#{public_project.id}/templates/metrics_dashboard_ymls/Default") + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to match_response_schema('public_api/v4/template') + expect(json_response['name']).to eq('Default') + end + it 'returns a specific license' do get api("/projects/#{public_project.id}/templates/licenses/mit") @@ -166,6 +183,10 @@ RSpec.describe API::ProjectTemplates do subject { get api("/projects/#{url_encoded_path}/templates/gitlab_ci_ymls/Android") } end + it_behaves_like 'accepts project paths with dots' do + subject { get api("/projects/#{url_encoded_path}/templates/metrics_dashboard_ymls/Default") } + end + shared_examples 'path traversal attempt' do |template_type| it 'rejects invalid filenames' do get api("/projects/#{public_project.id}/templates/#{template_type}/%2e%2e%2fPython%2ea") diff --git a/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb new file mode 100644 index 00000000000..6b6e25ca1dd --- /dev/null +++ b/spec/support/shared_examples/lib/gitlab/template/template_shared_examples.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.shared_examples 'file template shared examples' do |filename, file_extension| + describe '.all' do + it "strips the #{file_extension} suffix" do + expect(subject.all.first.name).not_to end_with(file_extension) + end + + it 'ensures that the template name is used exactly once' do + all = subject.all.group_by(&:name) + duplicates = all.select { |_, templates| templates.length > 1 } + + expect(duplicates).to be_empty + end + end + + describe '.by_category' do + it 'returns sorted results' do + result = described_class.by_category('General') + + expect(result).to eq(result.sort) + end + end + + describe '.find' do + it 'returns nil if the file does not exist' do + expect(subject.find('nonexistent-file')).to be nil + end + + it 'returns the corresponding object of a valid file' do + template = subject.find(filename) + + expect(template).to be_a described_class + expect(template.name).to eq(filename) + end + end + + describe '#<=>' do + it 'sorts lexicographically' do + one = described_class.new("a.#{file_extension}") + other = described_class.new("z.#{file_extension}") + + expect(one.<=>(other)).to be(-1) + expect([other, one].sort).to eq([one, other]) + end + end +end |