diff options
Diffstat (limited to 'spec/tooling')
-rw-r--r-- | spec/tooling/danger/customer_success_spec.rb | 91 | ||||
-rw-r--r-- | spec/tooling/graphql/docs/renderer_spec.rb | 122 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/find_codeowners_spec.rb | 43 | ||||
-rw-r--r-- | spec/tooling/quality/test_level_spec.rb | 4 |
4 files changed, 252 insertions, 8 deletions
diff --git a/spec/tooling/danger/customer_success_spec.rb b/spec/tooling/danger/customer_success_spec.rb new file mode 100644 index 00000000000..798905212f1 --- /dev/null +++ b/spec/tooling/danger/customer_success_spec.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'rspec-parameterized' +require 'gitlab-dangerfiles' +require 'gitlab/dangerfiles/spec_helper' +require_relative '../../../tooling/danger/customer_success' + +RSpec.describe Tooling::Danger::CustomerSuccess do + include_context "with dangerfile" + + let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } + let(:customer_success) { fake_danger.new(helper: fake_helper) } + + describe 'customer success danger' do + using RSpec::Parameterized::TableSyntax + + where do + { + 'with data category changes to Ops and no Customer Success::Impact Check label' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['-data_category: cat1', '+data_category: operational'], + customer_labeled: false, + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with data category changes and Customer Success::Impact Check label' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml), + changed_lines: ['-data_category: cat1', '+data_category: operational'], + customer_labeled: true, + impacted: false, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with metric file changes and no data category changes' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml), + changed_lines: ['-product_stage: growth'], + customer_labeled: false, + impacted: false, + impacted_files: [] + }, + 'with data category changes from Ops' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['-data_category: operational', '+data_category: cat2'], + customer_labeled: false, + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with data category removed' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['-data_category: operational'], + customer_labeled: false, + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with data category added' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+data_category: operational'], + customer_labeled: false, + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + }, + 'with data category in uppercase' => { + modified_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml app/models/user.rb), + changed_lines: ['+data_category: Operational'], + customer_labeled: false, + impacted: true, + impacted_files: %w(config/metrics/20210216182127_user_secret_detection_jobs.yml) + } + } + end + + with_them do + before do + allow(fake_helper).to receive(:modified_files).and_return(modified_files) + allow(fake_helper).to receive(:changed_lines).and_return(changed_lines) + allow(fake_helper).to receive(:has_scoped_label_with_scope?).and_return(customer_labeled) + allow(fake_helper).to receive(:markdown_list).with(impacted_files) + .and_return(impacted_files.map { |item| "* `#{item}`" }.join("\n")) + end + + it 'generates correct message' do + expect(customer_success.build_message).to match_expected_message + end + end + end + + def match_expected_message + return be_nil unless impacted + + start_with(described_class::CHANGED_SCHEMA_MESSAGE).and(include(*impacted_files)) + end +end diff --git a/spec/tooling/graphql/docs/renderer_spec.rb b/spec/tooling/graphql/docs/renderer_spec.rb index 18256fea2d6..bf2383507aa 100644 --- a/spec/tooling/graphql/docs/renderer_spec.rb +++ b/spec/tooling/graphql/docs/renderer_spec.rb @@ -347,6 +347,128 @@ RSpec.describe Tooling::Graphql::Docs::Renderer do it_behaves_like 'renders correctly as GraphQL documentation' end + context 'when an argument is in alpha' do + let(:type) do + Class.new(Types::BaseObject) do + graphql_name 'AlphaTest' + description 'A thing with arguments in alpha' + + field :foo, + type: GraphQL::Types::String, + null: false, + description: 'A description.' do + argument :foo_arg, GraphQL::Types::String, + required: false, + description: 'Argument description.', + alpha: { milestone: '101.2' } + end + end + end + + let(:section) do + <<~DOC + ##### `AlphaTest.foo` + + A description. + + Returns [`String!`](#string). + + ###### Arguments + + | Name | Type | Description | + | ---- | ---- | ----------- | + | <a id="alphatestfoofooarg"></a>`fooArg` **{warning-solid}** | [`String`](#string) | **Introduced** in 101.2. This feature is in Alpha. It can be changed or removed at any time. Argument description. | + DOC + end + + it_behaves_like 'renders correctly as GraphQL documentation' + end + + context 'when a field is in alpha' do + let(:type) do + Class.new(Types::BaseObject) do + graphql_name 'AlphaTest' + description 'A thing with fields in alpha' + + field :foo, + type: GraphQL::Types::String, + null: false, + alpha: { milestone: '1.10' }, + description: 'A description.' + field :foo_with_args, + type: GraphQL::Types::String, + null: false, + alpha: { milestone: '1.10' }, + description: 'A description.' do + argument :arg, GraphQL::Types::Int, required: false, description: 'Argity' + end + end + end + + let(:section) do + <<~DOC + ### `AlphaTest` + + A thing with fields in alpha. + + #### Fields + + | Name | Type | Description | + | ---- | ---- | ----------- | + | <a id="alphatestfoo"></a>`foo` **{warning-solid}** | [`String!`](#string) | **Introduced** in 1.10. This feature is in Alpha. It can be changed or removed at any time. A description. | + + #### Fields with arguments + + ##### `AlphaTest.fooWithArgs` + + A description. + + WARNING: + **Introduced** in 1.10. + This feature is in Alpha. It can be changed or removed at any time. + + Returns [`String!`](#string). + + ###### Arguments + + | Name | Type | Description | + | ---- | ---- | ----------- | + | <a id="alphatestfoowithargsarg"></a>`arg` | [`Int`](#int) | Argity. | + DOC + end + + it_behaves_like 'renders correctly as GraphQL documentation' + end + + context 'when a Query.field is in alpha' do + before do + query_type.field( + name: :bar, + type: type, + null: true, + description: 'A bar', + alpha: { milestone: '10.11' } + ) + end + + let(:type) { ::GraphQL::Types::Int } + let(:section) do + <<~DOC + ### `Query.bar` + + A bar. + + WARNING: + **Introduced** in 10.11. + This feature is in Alpha. It can be changed or removed at any time. + + Returns [`Int`](#int). + DOC + end + + it_behaves_like 'renders correctly as GraphQL documentation' + end + context 'when a field has an Enumeration type' do let(:type) do enum_type = Class.new(Types::BaseEnum) do diff --git a/spec/tooling/lib/tooling/find_codeowners_spec.rb b/spec/tooling/lib/tooling/find_codeowners_spec.rb index 10c2a076847..5f6f83ab2c7 100644 --- a/spec/tooling/lib/tooling/find_codeowners_spec.rb +++ b/spec/tooling/lib/tooling/find_codeowners_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Tooling::FindCodeowners do allow(subject).to receive(:load_config).and_return( '[Section name]': { '@group': { + entries: %w[whatever entries], allow: { keywords: %w[dir0 file], patterns: ['/%{keyword}/**/*', '/%{keyword}'] @@ -31,8 +32,11 @@ RSpec.describe Tooling::FindCodeowners do end end.to output(<<~CODEOWNERS).to_stdout [Section name] + whatever @group + entries @group /dir0/dir1/ @group /file @group + CODEOWNERS end end @@ -57,21 +61,33 @@ RSpec.describe Tooling::FindCodeowners do patterns: ['%{keyword}'] } } + }, + '[Compliance]': { + '@gitlab-org/manage/compliance': { + entries: %w[ + /ee/app/services/audit_events/build_service.rb + ], + allow: { + patterns: %w[ + /ee/app/services/audit_events/* + ] + } + } } } ) end it 'expands the allow and deny list with keywords and patterns' do - subject.load_definitions.each do |section, group_defintions| - group_defintions.each do |group, definitions| - expect(definitions[:allow]).to be_an(Array) - expect(definitions[:deny]).to be_an(Array) - end + group_defintions = subject.load_definitions[:'[Authentication and Authorization]'] + + group_defintions.each do |group, definitions| + expect(definitions[:allow]).to be_an(Array) + expect(definitions[:deny]).to be_an(Array) end end - it 'expands the auth group' do + it 'expands the patterns for the auth group' do auth = subject.load_definitions.dig( :'[Authentication and Authorization]', :'@gitlab-org/manage/authentication-and-authorization') @@ -95,6 +111,21 @@ RSpec.describe Tooling::FindCodeowners do ] ) end + + it 'retains the array and expands the patterns for the compliance group' do + compliance = subject.load_definitions.dig( + :'[Compliance]', + :'@gitlab-org/manage/compliance') + + expect(compliance).to eq( + entries: %w[ + /ee/app/services/audit_events/build_service.rb + ], + allow: %w[ + /ee/app/services/audit_events/* + ] + ) + end end describe '#load_config' do diff --git a/spec/tooling/quality/test_level_spec.rb b/spec/tooling/quality/test_level_spec.rb index 10afcb18a73..f4eea28b66f 100644 --- a/spec/tooling/quality/test_level_spec.rb +++ b/spec/tooling/quality/test_level_spec.rb @@ -46,7 +46,7 @@ RSpec.describe Quality::TestLevel do context 'when level is unit' do it 'returns a pattern' do expect(subject.pattern(:unit)) - .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,events,factories,finders,frontend,graphql,haml_lint,helpers,initializers,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling,components}{,/**/}*_spec.rb") + .to eq("spec/{bin,channels,config,db,dependencies,elastic,elastic_integration,experiments,factories,finders,frontend,graphql,haml_lint,helpers,initializers,lib,metrics_server,models,policies,presenters,rack_servers,replicators,routing,rubocop,scripts,serializers,services,sidekiq,sidekiq_cluster,spam,support_specs,tasks,uploaders,validators,views,workers,tooling,components}{,/**/}*_spec.rb") end end @@ -121,7 +121,7 @@ RSpec.describe Quality::TestLevel do context 'when level is unit' do it 'returns a regexp' do expect(subject.regexp(:unit)) - .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|events|factories|finders|frontend|graphql|haml_lint|helpers|initializers|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling|components)/}) + .to eq(%r{spec/(bin|channels|config|db|dependencies|elastic|elastic_integration|experiments|factories|finders|frontend|graphql|haml_lint|helpers|initializers|lib|metrics_server|models|policies|presenters|rack_servers|replicators|routing|rubocop|scripts|serializers|services|sidekiq|sidekiq_cluster|spam|support_specs|tasks|uploaders|validators|views|workers|tooling|components)/}) end end |