diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 09:07:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-30 09:07:58 +0000 |
commit | 45b4df3e57c949c88107840c44ccbfaf2eabdf26 (patch) | |
tree | f73c1533a75b03d2ceb1361644e0d8ab97568a8f /spec | |
parent | 7421e6f9f2b5889b05738af7eba568af6ae3fcbc (diff) | |
download | gitlab-ce-45b4df3e57c949c88107840c44ccbfaf2eabdf26.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
10 files changed, 161 insertions, 122 deletions
diff --git a/spec/lib/gitlab/hook_data/issue_builder_spec.rb b/spec/lib/gitlab/hook_data/issue_builder_spec.rb index 168603d6fcc..1f681faa8f7 100644 --- a/spec/lib/gitlab/hook_data/issue_builder_spec.rb +++ b/spec/lib/gitlab/hook_data/issue_builder_spec.rb @@ -18,6 +18,7 @@ describe Gitlab::HookData::IssueBuilder do confidential created_at description + discussion_locked due_date id iid diff --git a/spec/lib/gitlab/import_export/group/tree_saver_spec.rb b/spec/lib/gitlab/import_export/group/tree_saver_spec.rb index 44fd49f0ac3..eb790662d8c 100644 --- a/spec/lib/gitlab/import_export/group/tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/group/tree_saver_spec.rb @@ -23,50 +23,6 @@ describe Gitlab::ImportExport::Group::TreeSaver do expect(group_tree_saver.save).to be true end - context ':export_fast_serialize feature flag checks' do - before do - expect(Gitlab::ImportExport::Reader).to receive(:new).with(shared: shared, config: group_config).and_return(reader) - expect(reader).to receive(:group_tree).and_return(group_tree) - end - - let(:reader) { instance_double('Gitlab::ImportExport::Reader') } - let(:group_config) { Gitlab::ImportExport::Config.new(config: Gitlab::ImportExport.group_config_file).to_h } - let(:group_tree) do - { - include: [{ milestones: { include: [] } }], - preload: { milestones: nil } - } - end - - context 'when :export_fast_serialize feature is enabled' do - let(:serializer) { instance_double(Gitlab::ImportExport::FastHashSerializer) } - - before do - stub_feature_flags(export_fast_serialize: true) - - expect(Gitlab::ImportExport::FastHashSerializer).to receive(:new).with(group, group_tree).and_return(serializer) - end - - it 'uses FastHashSerializer' do - expect(serializer).to receive(:execute) - - group_tree_saver.save - end - end - - context 'when :export_fast_serialize feature is disabled' do - before do - stub_feature_flags(export_fast_serialize: false) - end - - it 'is serialized via built-in `as_json`' do - expect(group).to receive(:as_json).with(group_tree).and_call_original - - group_tree_saver.save - end - end - end - # It is mostly duplicated in # `spec/lib/gitlab/import_export/fast_hash_serializer_spec.rb` # except: diff --git a/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb b/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb index db77bd338e1..958865f52a0 100644 --- a/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/legacy_relation_tree_saver_spec.rb @@ -8,35 +8,17 @@ describe Gitlab::ImportExport::LegacyRelationTreeSaver do let(:tree) { {} } describe '#serialize' do - context 'when :export_fast_serialize feature is enabled' do - let(:serializer) { instance_double(Gitlab::ImportExport::FastHashSerializer) } + let(:serializer) { instance_double(Gitlab::ImportExport::FastHashSerializer) } - before do - stub_feature_flags(export_fast_serialize: true) - end + it 'uses FastHashSerializer' do + expect(Gitlab::ImportExport::FastHashSerializer) + .to receive(:new) + .with(exportable, tree) + .and_return(serializer) - it 'uses FastHashSerializer' do - expect(Gitlab::ImportExport::FastHashSerializer) - .to receive(:new) - .with(exportable, tree) - .and_return(serializer) + expect(serializer).to receive(:execute) - expect(serializer).to receive(:execute) - - relation_tree_saver.serialize(exportable, tree) - end - end - - context 'when :export_fast_serialize feature is disabled' do - before do - stub_feature_flags(export_fast_serialize: false) - end - - it 'is serialized via built-in `as_json`' do - expect(exportable).to receive(:as_json).with(tree) - - relation_tree_saver.serialize(exportable, tree) - end + relation_tree_saver.serialize(exportable, tree) end end end diff --git a/spec/lib/gitlab/import_export/project/legacy_tree_saver_spec.rb b/spec/lib/gitlab/import_export/project/legacy_tree_saver_spec.rb index d4406dbc60b..e51f6888bbb 100644 --- a/spec/lib/gitlab/import_export/project/legacy_tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project/legacy_tree_saver_spec.rb @@ -25,51 +25,6 @@ describe Gitlab::ImportExport::Project::LegacyTreeSaver do expect(project_tree_saver.save).to be true end - context ':export_fast_serialize feature flag checks' do - before do - expect(Gitlab::ImportExport::Reader).to receive(:new).with(shared: shared).and_return(reader) - expect(reader).to receive(:project_tree).and_return(project_tree) - end - - let(:serializer) { instance_double('Gitlab::ImportExport::FastHashSerializer') } - let(:reader) { instance_double('Gitlab::ImportExport::Reader') } - let(:project_tree) do - { - include: [{ issues: { include: [] } }], - preload: { issues: nil } - } - end - - context 'when :export_fast_serialize feature is enabled' do - before do - stub_feature_flags(export_fast_serialize: true) - end - - it 'uses FastHashSerializer' do - expect(Gitlab::ImportExport::FastHashSerializer) - .to receive(:new) - .with(project, project_tree) - .and_return(serializer) - - expect(serializer).to receive(:execute) - - project_tree_saver.save - end - end - - context 'when :export_fast_serialize feature is disabled' do - before do - stub_feature_flags(export_fast_serialize: false) - end - - it 'is serialized via built-in `as_json`' do - expect(project).to receive(:as_json).with(project_tree) - - project_tree_saver.save - end - end - end - # It is mostly duplicated in # `spec/lib/gitlab/import_export/fast_hash_serializer_spec.rb` # except: diff --git a/spec/models/container_registry/event_spec.rb b/spec/models/container_registry/event_spec.rb new file mode 100644 index 00000000000..54ff218f2a8 --- /dev/null +++ b/spec/models/container_registry/event_spec.rb @@ -0,0 +1,92 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ContainerRegistry::Event do + using RSpec::Parameterized::TableSyntax + + let_it_be(:group) { create(:group, name: 'group') } + let_it_be(:project) { create(:project, name: 'test', namespace: group) } + + describe '#supported?' do + let(:raw_event) { { 'action' => action } } + + subject { described_class.new(raw_event).supported? } + + where(:action, :supported) do + 'delete' | true + 'push' | true + 'mount' | false + 'pull' | false + end + + with_them do + it { is_expected.to eq supported } + end + end + + describe '#handle!' do + let(:raw_event) { { 'action' => 'push', 'target' => { 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE } } } + + subject { described_class.new(raw_event).handle! } + + it { is_expected.to eq nil } + end + + describe '#track!' do + let_it_be(:container_repository) { create(:container_repository, name: 'container', project: project) } + + let(:raw_event) { { 'action' => action, 'target' => target } } + + subject { described_class.new(raw_event).track! } + + context 'with a respository target' do + let(:target) do + { + 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE, + 'repository' => repository_path + } + end + + where(:repository_path, :action, :tracking_action) do + 'group/test/container' | 'push' | 'push_repository' + 'group/test/container' | 'delete' | 'delete_repository' + 'foo/bar' | 'push' | 'create_repository' + 'foo/bar' | 'delete' | 'delete_repository' + end + + with_them do + it 'creates a tracking event' do + expect(::Gitlab::Tracking).to receive(:event).with('container_registry:notification', tracking_action) + + subject + end + end + end + + context 'with a tag target' do + let(:target) do + { + 'mediaType' => ContainerRegistry::Client::DOCKER_DISTRIBUTION_MANIFEST_V2_TYPE, + 'repository' => repository_path, + 'tag' => 'latest' + } + end + + where(:repository_path, :action, :tracking_action) do + 'group/test/container' | 'push' | 'push_tag' + 'group/test/container' | 'delete' | 'delete_tag' + 'foo/bar' | 'push' | 'push_tag' + 'foo/bar' | 'delete' | 'delete_tag' + end + + with_them do + it 'creates a tracking event' do + expect(::Gitlab::Tracking).to receive(:event).with('container_registry:notification', tracking_action) + + subject + end + end + end + end +end diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index 5ed812652c5..5bcd9dfd396 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -29,6 +29,18 @@ describe ContainerRepository do end end + describe '.exists_by_path?' do + it 'returns true for known container repository paths' do + path = ContainerRegistry::Path.new("#{project.full_path}/#{repository.name}") + expect(described_class.exists_by_path?(path)).to be_truthy + end + + it 'returns false for unknown container repository paths' do + path = ContainerRegistry::Path.new('you/dont/know/me') + expect(described_class.exists_by_path?(path)).to be_falsey + end + end + describe '#tag' do it 'has a test tag' do expect(repository.tag('test')).not_to be_nil diff --git a/spec/requests/api/container_registry_event_spec.rb b/spec/requests/api/container_registry_event_spec.rb new file mode 100644 index 00000000000..9c144f80fd4 --- /dev/null +++ b/spec/requests/api/container_registry_event_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::ContainerRegistryEvent do + let(:secret_token) { 'secret_token' } + let(:events) { [{ action: 'push' }] } + let(:registry_headers) { { 'Content-Type' => ::API::ContainerRegistryEvent::DOCKER_DISTRIBUTION_EVENTS_V1_JSON } } + + describe 'POST /container_registry_event/events' do + before do + allow(Gitlab.config.registry).to receive(:notification_secret) { secret_token } + end + + subject do + post api('/container_registry_event/events'), + params: { events: events }.to_json, + headers: registry_headers.merge('Authorization' => secret_token) + end + + it 'returns 200 status and events are passed to event handler' do + event = spy(:event) + allow(::ContainerRegistry::Event).to receive(:new).and_return(event) + expect(event).to receive(:supported?).and_return(true) + + subject + + expect(event).to have_received(:handle!).once + expect(event).to have_received(:track!).once + expect(response.status).to eq 200 + end + + it 'returns 401 error status when token is invalid' do + post api('/container_registry_event/events'), + params: { events: events }.to_json, + headers: registry_headers.merge('Authorization' => 'invalid_token') + + expect(response.status).to eq 401 + end + end +end diff --git a/spec/requests/api/graphql/namespace/root_storage_statistics_spec.rb b/spec/requests/api/graphql/namespace/root_storage_statistics_spec.rb index ac76d991bd4..f7e28043930 100644 --- a/spec/requests/api/graphql/namespace/root_storage_statistics_spec.rb +++ b/spec/requests/api/graphql/namespace/root_storage_statistics_spec.rb @@ -6,7 +6,7 @@ describe 'rendering namespace statistics' do include GraphqlHelpers let(:namespace) { user.namespace } - let!(:statistics) { create(:namespace_root_storage_statistics, namespace: namespace, packages_size: 5.megabytes) } + let!(:statistics) { create(:namespace_root_storage_statistics, namespace: namespace, packages_size: 5.gigabytes) } let(:user) { create(:user) } let(:query) do @@ -26,7 +26,7 @@ describe 'rendering namespace statistics' do post_graphql(query, current_user: user) expect(graphql_data['namespace']['rootStorageStatistics']).not_to be_blank - expect(graphql_data['namespace']['rootStorageStatistics']['packagesSize']).to eq(5.megabytes) + expect(graphql_data['namespace']['rootStorageStatistics']['packagesSize']).to eq(5.gigabytes) end end diff --git a/spec/requests/api/graphql/project/project_statistics_spec.rb b/spec/requests/api/graphql/project/project_statistics_spec.rb index ddee8537454..05dd5d36c26 100644 --- a/spec/requests/api/graphql/project/project_statistics_spec.rb +++ b/spec/requests/api/graphql/project/project_statistics_spec.rb @@ -6,7 +6,7 @@ describe 'rendering project statistics' do include GraphqlHelpers let(:project) { create(:project) } - let!(:project_statistics) { create(:project_statistics, project: project, packages_size: 5.megabytes) } + let!(:project_statistics) { create(:project_statistics, project: project, packages_size: 5.gigabytes) } let(:user) { create(:user) } let(:query) do @@ -28,7 +28,7 @@ describe 'rendering project statistics' do it "includes the packages size if the user can read the statistics" do post_graphql(query, current_user: user) - expect(graphql_data['project']['statistics']['packagesSize']).to eq(5.megabytes) + expect(graphql_data['project']['statistics']['packagesSize']).to eq(5.gigabytes) end context 'when the project is public' do diff --git a/spec/requests/api/project_templates_spec.rb b/spec/requests/api/project_templates_spec.rb index 50b950fb5c1..5dabce20043 100644 --- a/spec/requests/api/project_templates_spec.rb +++ b/spec/requests/api/project_templates_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe API::ProjectTemplates do - let(:public_project) { create(:project, :public) } - let(:private_project) { create(:project, :private) } - let(:developer) { create(:user) } + let_it_be(:public_project) { create(:project, :public) } + let_it_be(:private_project) { create(:project, :private) } + let_it_be(:developer) { create(:user) } before do private_project.add_developer(developer) |