diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-03 00:08:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-03 00:08:11 +0000 |
commit | bd8fb5668ae739a83d55ec5ca4a04344eef2167e (patch) | |
tree | baf085c6cd58b3b5e5a192d4d3db360d623bb056 /spec | |
parent | 561e1b470f0a99fe6304c8f197348c47a637d594 (diff) | |
download | gitlab-ce-bd8fb5668ae739a83d55ec5ca4a04344eef2167e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
8 files changed, 162 insertions, 132 deletions
diff --git a/spec/features/merge_request/maintainer_edits_fork_spec.rb b/spec/features/merge_request/maintainer_edits_fork_spec.rb index 17ff494a6fa..f1ee6aaa897 100644 --- a/spec/features/merge_request/maintainer_edits_fork_spec.rb +++ b/spec/features/merge_request/maintainer_edits_fork_spec.rb @@ -20,7 +20,7 @@ describe 'a maintainer edits files on a source-branch of an MR from a fork', :js end before do - stub_feature_flags(web_ide_default: false, single_mr_diff_view: false, code_navigation: false) + stub_feature_flags(web_ide_default: false, single_mr_diff_view: { enabled: false, thing: target_project }, code_navigation: false) target_project.add_maintainer(user) sign_in(user) diff --git a/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb b/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb index 92d90926c0a..8633d67f875 100644 --- a/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb +++ b/spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb @@ -10,7 +10,7 @@ describe 'Batch diffs', :js do let(:merge_request) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'empty-branch') } before do - stub_feature_flags(single_mr_diff_view: true) + stub_feature_flags(single_mr_diff_view: { enabled: true, thing: project }) stub_feature_flags(diffs_batch_load: true) sign_in(project.owner) diff --git a/spec/fixtures/lib/gitlab/import_export/complex/project.json b/spec/fixtures/lib/gitlab/import_export/complex/project.json index 4d6211a1251..fae02540868 100644 --- a/spec/fixtures/lib/gitlab/import_export/complex/project.json +++ b/spec/fixtures/lib/gitlab/import_export/complex/project.json @@ -6318,7 +6318,7 @@ ] } ], - "pipelines": [ + "ci_pipelines": [ { "id": 36, "project_id": 5, diff --git a/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb b/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb index 9ac06a90efd..2092b9e9db8 100644 --- a/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb +++ b/spec/lib/banzai/filter/inline_grafana_metrics_filter_spec.rb @@ -10,18 +10,20 @@ describe Banzai::Filter::InlineGrafanaMetricsFilter do let(:input) { %(<a href="#{trigger_url}">example</a>) } let(:doc) { filter(input) } + let(:embed_url) { doc.at_css('.js-render-metrics')['data-dashboard-url'] } + let(:dashboard_path) do '/d/XDaNK6amz/gitlab-omnibus-redis' \ - '?from=1570397739557&to=1570484139557' \ - '&var-instance=All&panelId=14' + '?from=1570397739557&panelId=14' \ + '&to=1570484139557&var-instance=All' end let(:trigger_url) { grafana_integration.grafana_url + dashboard_path } let(:dashboard_url) do urls.project_grafana_api_metrics_dashboard_url( project, - embedded: true, grafana_url: trigger_url, + embedded: true, start: "2019-10-06T21:35:39Z", end: "2019-10-07T21:35:39Z" ) @@ -29,6 +31,10 @@ describe Banzai::Filter::InlineGrafanaMetricsFilter do it_behaves_like 'a metrics embed filter' + around do |example| + Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run } + end + context 'when grafana is not configured' do before do allow(project).to receive(:grafana_integration).and_return(nil) @@ -39,7 +45,7 @@ describe Banzai::Filter::InlineGrafanaMetricsFilter do end end - context 'when parameters are missing' do + context 'when "panelId" parameter is missing' do let(:dashboard_path) { '/d/XDaNK6amz/gitlab-omnibus-redis' } it 'leaves the markdown unchanged' do @@ -47,6 +53,39 @@ describe Banzai::Filter::InlineGrafanaMetricsFilter do end end + context 'when time window parameters are missing' do + let(:dashboard_path) { '/d/XDaNK6amz/gitlab-omnibus-redis?panelId=16' } + + it 'sets the window to the last 8 hrs' do + expect(embed_url).to include( + 'from%3D1552799400000', 'to%3D1552828200000', + 'start=2019-03-17T05%3A10%3A00Z', 'end=2019-03-17T13%3A10%3A00Z' + ) + end + end + + context 'when "to" parameter is missing' do + let(:dashboard_path) { '/d/XDaNK6amz/gitlab-omnibus-redis?panelId=16&from=1570397739557' } + + it 'sets "to" to 8 hrs after "from"' do + expect(embed_url).to include( + 'from%3D1570397739557', 'to%3D1570426539000', + 'start=2019-10-06T21%3A35%3A39Z', 'end=2019-10-07T05%3A35%3A39Z' + ) + end + end + + context 'when "from" parameter is missing' do + let(:dashboard_path) { '/d/XDaNK6amz/gitlab-omnibus-redis?panelId=16&to=1570484139557' } + + it 'sets "from" to 8 hrs before "to"' do + expect(embed_url).to include( + 'from%3D1570455339000', 'to%3D1570484139557', + 'start=2019-10-07T13%3A35%3A39Z', 'end=2019-10-07T21%3A35%3A39Z' + ) + end + end + private # Nokogiri escapes the URLs, but we don't care about that diff --git a/spec/lib/gitlab/import_export/import_test_coverage_spec.rb b/spec/lib/gitlab/import_export/import_test_coverage_spec.rb index 97d5ce07d47..335b0031147 100644 --- a/spec/lib/gitlab/import_export/import_test_coverage_spec.rb +++ b/spec/lib/gitlab/import_export/import_test_coverage_spec.rb @@ -89,8 +89,6 @@ describe 'Test coverage of the Project Import' do def relations_from_json(json_file) json = ActiveSupport::JSON.decode(IO.read(json_file)) - Gitlab::ImportExport::RelationRenameService.rename(json) - [].tap {|res| gather_relations({ project: json }, res, [])} .map {|relation_names| relation_names.join('.')} end diff --git a/spec/lib/gitlab/import_export/relation_rename_service_spec.rb b/spec/lib/gitlab/import_export/relation_rename_service_spec.rb deleted file mode 100644 index 2e251154e9f..00000000000 --- a/spec/lib/gitlab/import_export/relation_rename_service_spec.rb +++ /dev/null @@ -1,122 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::ImportExport::RelationRenameService do - include ImportExport::CommonUtil - - let(:renames) do - { - 'example_relation1' => 'new_example_relation1', - 'example_relation2' => 'new_example_relation2' - } - end - - let(:user) { create(:admin) } - let(:group) { create(:group, :nested) } - let!(:project) { create(:project, :builds_disabled, :issues_disabled, group: group, name: 'project', path: 'project') } - let(:shared) { project.import_export_shared } - - before do - stub_const("#{described_class}::RENAMES", renames) - end - - context 'when importing' do - let(:project_tree_restorer) { Gitlab::ImportExport::Project::TreeRestorer.new(user: user, shared: shared, project: project) } - let(:file_content) { IO.read(File.join(shared.export_path, 'project.json')) } - let(:json_file) { ActiveSupport::JSON.decode(file_content) } - - before do - setup_import_export_config('complex') - - allow(ActiveSupport::JSON).to receive(:decode).and_call_original - allow(ActiveSupport::JSON).to receive(:decode).with(file_content).and_return(json_file) - end - - context 'when the file has only old relationship names' do - # Configuring the json as an old version exported file, with only - # the previous association with the old name - before do - renames.each do |old_name, _| - json_file[old_name.to_s] = [] - end - end - - it 'renames old relationships to the new name' do - expect(json_file.keys).to include(*renames.keys) - - project_tree_restorer.restore - - expect(json_file.keys).to include(*renames.values) - expect(json_file.keys).not_to include(*renames.keys) - end - end - - context 'when the file has both the old and new relationships' do - # Configuring the json as the new version exported file, with both - # the old association name and the new one - before do - renames.each do |old_name, new_name| - json_file[old_name.to_s] = [1] - json_file[new_name.to_s] = [2] - end - end - - it 'uses the new relationships and removes the old ones from the hash' do - expect(json_file.keys).to include(*renames.keys) - - project_tree_restorer.restore - - expect(json_file.keys).to include(*renames.values) - expect(json_file.values_at(*renames.values).flatten.uniq.first).to eq 2 - expect(json_file.keys).not_to include(*renames.keys) - end - end - - context 'when the file has only new relationship names' do - # Configuring the json as the future version exported file, with only - # the new association name - before do - renames.each do |_, new_name| - json_file[new_name.to_s] = [] - end - end - - it 'uses the new relationships' do - expect(json_file.keys).not_to include(*renames.keys) - - project_tree_restorer.restore - - expect(json_file.keys).to include(*renames.values) - end - end - end - - context 'when exporting' do - let(:export_content_path) { project_tree_saver.full_path } - let(:export_content_hash) { ActiveSupport::JSON.decode(File.read(export_content_path)) } - let(:injected_hash) { renames.values.product([{}]).to_h } - let(:relation_tree_saver) { Gitlab::ImportExport::RelationTreeSaver.new } - - let(:project_tree_saver) do - Gitlab::ImportExport::Project::TreeSaver.new( - project: project, current_user: user, shared: shared) - end - - before do - allow(project_tree_saver).to receive(:tree_saver).and_return(relation_tree_saver) - end - - it 'adds old relationships to the exported file' do - # we inject relations with new names that should be rewritten - expect(relation_tree_saver).to receive(:serialize).and_wrap_original do |method, *args| - method.call(*args).merge(injected_hash) - end - - expect(project_tree_saver.save).to eq(true) - - expect(export_content_hash.keys).to include(*renames.keys) - expect(export_content_hash.keys).to include(*renames.values) - end - end -end diff --git a/spec/lib/grafana/time_window_spec.rb b/spec/lib/grafana/time_window_spec.rb new file mode 100644 index 00000000000..e70861658ca --- /dev/null +++ b/spec/lib/grafana/time_window_spec.rb @@ -0,0 +1,115 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Grafana::TimeWindow do + let(:from) { '1552799400000' } + let(:to) { '1552828200000' } + + around do |example| + Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run } + end + + describe '#formatted' do + subject { described_class.new(from, to).formatted } + + it { is_expected.to eq(start: "2019-03-17T05:10:00Z", end: "2019-03-17T13:10:00Z") } + end + + describe '#in_milliseconds' do + subject { described_class.new(from, to).in_milliseconds } + + it { is_expected.to eq(from: 1552799400000, to: 1552828200000) } + + context 'when non-unix parameters are provided' do + let(:to) { Time.now.to_s } + + let(:default_from) { 8.hours.ago.to_i * 1000 } + let(:default_to) { Time.now.to_i * 1000 } + + it { is_expected.to eq(from: default_from, to: default_to) } + end + end +end + +describe Grafana::RangeWithDefaults do + let(:from) { Grafana::Timestamp.from_ms_since_epoch('1552799400000') } + let(:to) { Grafana::Timestamp.from_ms_since_epoch('1552828200000') } + + around do |example| + Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run } + end + + describe '#to_hash' do + subject { described_class.new(from: from, to: to).to_hash } + + it { is_expected.to eq(from: from, to: to) } + + context 'when only "to" is provided' do + let(:from) { nil } + + it 'has the expected properties' do + expect(subject[:to]).to eq(to) + expect(subject[:from].time).to eq(to.time - 8.hours) + end + end + + context 'when only "from" is provided' do + let(:to) { nil } + + it 'has the expected properties' do + expect(subject[:to].time).to eq(from.time + 8.hours) + expect(subject[:from]).to eq(from) + end + end + + context 'when no parameters are provided' do + let(:to) { nil } + let(:from) { nil } + + let(:default_from) { 8.hours.ago } + let(:default_to) { Time.now } + + it 'has the expected properties' do + expect(subject[:to].time).to eq(default_to) + expect(subject[:from].time).to eq(default_from) + end + end + end +end + +describe Grafana::Timestamp do + let(:timestamp) { Time.at(1552799400) } + + around do |example| + Timecop.freeze(Time.utc(2019, 3, 17, 13, 10)) { example.run } + end + + describe '#formatted' do + subject { described_class.new(timestamp).formatted } + + it { is_expected.to eq "2019-03-17T05:10:00Z" } + end + + describe '#to_ms' do + subject { described_class.new(timestamp).to_ms } + + it { is_expected.to eq 1552799400000 } + end + + describe '.from_ms_since_epoch' do + let(:timestamp) { '1552799400000' } + + subject { described_class.from_ms_since_epoch(timestamp) } + + it { is_expected.to be_a described_class } + + context 'when the input is not a unix-ish timestamp' do + let(:timestamp) { Time.now.to_s } + + it 'raises an error' do + expect { subject }.to raise_error(Grafana::Timestamp::Error) + end + end + end +end diff --git a/spec/support/shared_examples/serializers/diff_file_entity_shared_examples.rb b/spec/support/shared_examples/serializers/diff_file_entity_shared_examples.rb index db5c4b45b70..b6c4841dbd4 100644 --- a/spec/support/shared_examples/serializers/diff_file_entity_shared_examples.rb +++ b/spec/support/shared_examples/serializers/diff_file_entity_shared_examples.rb @@ -60,7 +60,7 @@ RSpec.shared_examples 'diff file entity' do context 'when the `single_mr_diff_view` feature is disabled' do before do - stub_feature_flags(single_mr_diff_view: false) + stub_feature_flags(single_mr_diff_view: { enabled: false, thing: project }) end it 'contains both kinds of diffs' do |