diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 13:49:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 13:49:51 +0000 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /spec/tooling/lib | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) | |
download | gitlab-ce-71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e.tar.gz |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'spec/tooling/lib')
-rw-r--r-- | spec/tooling/lib/tooling/helm3_client_spec.rb | 48 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/kubernetes_client_spec.rb | 20 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/mappings/base_spec.rb | 44 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb | 169 | ||||
-rw-r--r-- | spec/tooling/lib/tooling/mappings/view_to_js_mappings_spec.rb (renamed from spec/tooling/lib/tooling/view_to_js_mappings_spec.rb) | 49 |
5 files changed, 254 insertions, 76 deletions
diff --git a/spec/tooling/lib/tooling/helm3_client_spec.rb b/spec/tooling/lib/tooling/helm3_client_spec.rb index 52d1b5a1567..5a015ddfa7c 100644 --- a/spec/tooling/lib/tooling/helm3_client_spec.rb +++ b/spec/tooling/lib/tooling/helm3_client_spec.rb @@ -3,15 +3,14 @@ require_relative '../../../../tooling/lib/tooling/helm3_client' RSpec.describe Tooling::Helm3Client do - let(:namespace) { 'review-apps' } let(:release_name) { 'my-release' } let(:raw_helm_list_page1) do <<~OUTPUT [ - {"name":"review-qa-60-reor-1mugd1","namespace":"#{namespace}","revision":1,"updated":"2020-04-03 17:27:10.245952 +0800 +08","status":"failed","chart":"gitlab-1.1.3","app_version":"12.9.2"}, - {"name":"review-7846-fix-s-261vd6","namespace":"#{namespace}","revision":2,"updated":"2020-04-02 17:27:12.245952 +0800 +08","status":"deployed","chart":"gitlab-1.1.3","app_version":"12.9.2"}, - {"name":"review-7867-snowp-lzo3iy","namespace":"#{namespace}","revision":1,"updated":"2020-04-02 15:27:12.245952 +0800 +08","status":"deployed","chart":"gitlab-1.1.3","app_version":"12.9.1"}, - {"name":"review-6709-group-2pzeec","namespace":"#{namespace}","revision":2,"updated":"2020-04-01 21:27:12.245952 +0800 +08","status":"failed","chart":"gitlab-1.1.3","app_version":"12.9.1"} + {"name":"review-qa-60-reor-1mugd1","namespace":"review-qa-60-reor-1mugd1","revision":1,"updated":"2020-04-03 17:27:10.245952 +0800 +08","status":"failed","chart":"gitlab-1.1.3","app_version":"12.9.2"}, + {"name":"review-7846-fix-s-261vd6","namespace":"review-7846-fix-s-261vd6","revision":2,"updated":"2020-04-02 17:27:12.245952 +0800 +08","status":"deployed","chart":"gitlab-1.1.3","app_version":"12.9.2"}, + {"name":"review-7867-snowp-lzo3iy","namespace":"review-7867-snowp-lzo3iy","revision":1,"updated":"2020-04-02 15:27:12.245952 +0800 +08","status":"deployed","chart":"gitlab-1.1.3","app_version":"12.9.1"}, + {"name":"review-6709-group-2pzeec","namespace":"review-6709-group-2pzeec","revision":2,"updated":"2020-04-01 21:27:12.245952 +0800 +08","status":"failed","chart":"gitlab-1.1.3","app_version":"12.9.1"} ] OUTPUT end @@ -19,7 +18,7 @@ RSpec.describe Tooling::Helm3Client do let(:raw_helm_list_page2) do <<~OUTPUT [ - {"name":"review-6709-group-t40qbv","namespace":"#{namespace}","revision":2,"updated":"2020-04-01 11:27:12.245952 +0800 +08","status":"deployed","chart":"gitlab-1.1.3","app_version":"12.9.1"} + {"name":"review-6709-group-t40qbv","namespace":"review-6709-group-t40qbv","revision":2,"updated":"2020-04-01 11:27:12.245952 +0800 +08","status":"deployed","chart":"gitlab-1.1.3","app_version":"12.9.1"} ] OUTPUT end @@ -30,7 +29,7 @@ RSpec.describe Tooling::Helm3Client do OUTPUT end - subject { described_class.new(namespace: namespace) } + subject { described_class.new } describe '#releases' do it 'raises an error if the Helm command fails' do @@ -74,7 +73,7 @@ RSpec.describe Tooling::Helm3Client do status: 'deployed', chart: 'gitlab-1.1.3', app_version: '12.9.1', - namespace: namespace + namespace: 'review-6709-group-t40qbv' ) end @@ -98,18 +97,19 @@ RSpec.describe Tooling::Helm3Client do describe '#delete' do it 'raises an error if the Helm command fails' do expect(Gitlab::Popen).to receive(:popen_with_detail) - .with([%(helm uninstall #{release_name})]) + .with([%(helm uninstall --namespace #{release_name} #{release_name})]) .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: false))) - expect { subject.delete(release_name: release_name) }.to raise_error(described_class::CommandFailedError) + expect { subject.delete(release_name: release_name, namespace: release_name) } + .to raise_error(described_class::CommandFailedError) end it 'calls helm uninstall with default arguments' do expect(Gitlab::Popen).to receive(:popen_with_detail) - .with([%(helm uninstall #{release_name})]) + .with([%(helm uninstall --namespace #{release_name} #{release_name})]) .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) - expect(subject.delete(release_name: release_name)).to eq('') + subject.delete(release_name: release_name, namespace: release_name) end context 'with multiple release names' do @@ -117,18 +117,30 @@ RSpec.describe Tooling::Helm3Client do it 'raises an error if the Helm command fails' do expect(Gitlab::Popen).to receive(:popen_with_detail) - .with([%(helm uninstall #{release_name.join(' ')})]) + .with([%(helm uninstall --namespace #{release_name[0]} #{release_name[0]})]) .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: false))) expect { subject.delete(release_name: release_name) }.to raise_error(described_class::CommandFailedError) end - it 'calls helm uninstall with multiple release names' do - expect(Gitlab::Popen).to receive(:popen_with_detail) - .with([%(helm uninstall #{release_name.join(' ')})]) - .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) + it 'calls helm uninstall with multiple release names and a namespace' do + release_name.each do |release| + expect(Gitlab::Popen).to receive(:popen_with_detail) + .with([%(helm uninstall --namespace namespace #{release})]) + .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) + end + + subject.delete(release_name: release_name, namespace: 'namespace') + end + + it 'calls helm uninstall with multiple release names and no namespace' do + release_name.each do |release| + expect(Gitlab::Popen).to receive(:popen_with_detail) + .with([%(helm uninstall --namespace #{release} #{release})]) + .and_return(Gitlab::Popen::Result.new([], '', '', double(success?: true))) + end - expect(subject.delete(release_name: release_name)).to eq('') + subject.delete(release_name: release_name) end end end diff --git a/spec/tooling/lib/tooling/kubernetes_client_spec.rb b/spec/tooling/lib/tooling/kubernetes_client_spec.rb index a7f50b0bb50..50d33182a42 100644 --- a/spec/tooling/lib/tooling/kubernetes_client_spec.rb +++ b/spec/tooling/lib/tooling/kubernetes_client_spec.rb @@ -250,7 +250,7 @@ RSpec.describe Tooling::KubernetesClient do describe '#review_app_namespaces_created_before' do let(:three_days_ago) { Time.now - 3600 * 24 * 3 } let(:two_days_ago) { Time.now - 3600 * 24 * 2 } - let(:namespace_created_three_days_ago) { 'namespace-created-three-days-ago' } + let(:namespace_created_three_days_ago) { 'review-ns-created-three-days-ago' } let(:resource_type) { 'namespace' } let(:raw_resources) do { @@ -260,10 +260,7 @@ RSpec.describe Tooling::KubernetesClient do kind: "Namespace", metadata: { creationTimestamp: three_days_ago, - name: namespace_created_three_days_ago, - labels: { - tls: 'review-apps-tls' - } + name: namespace_created_three_days_ago } }, { @@ -271,10 +268,7 @@ RSpec.describe Tooling::KubernetesClient do kind: "Namespace", metadata: { creationTimestamp: Time.now, - name: 'another-pvc', - labels: { - tls: 'review-apps-tls' - } + name: 'another-namespace' } } ] @@ -283,12 +277,10 @@ RSpec.describe Tooling::KubernetesClient do specify do expect(Gitlab::Popen).to receive(:popen_with_detail) - .with(["kubectl get namespace " \ - "-l tls=review-apps-tls " \ - "--sort-by='{.metadata.creationTimestamp}' -o json"]) - .and_return(Gitlab::Popen::Result.new([], raw_resources, '', double(success?: true))) + .with(["kubectl get namespace --sort-by='{.metadata.creationTimestamp}' -o json"]) + .and_return(Gitlab::Popen::Result.new([], raw_resources, '', double(success?: true))) - expect(subject.__send__(:review_app_namespaces_created_before, created_before: two_days_ago)).to contain_exactly(namespace_created_three_days_ago) + expect(subject.__send__(:review_app_namespaces_created_before, created_before: two_days_ago)).to eq([namespace_created_three_days_ago]) end end end diff --git a/spec/tooling/lib/tooling/mappings/base_spec.rb b/spec/tooling/lib/tooling/mappings/base_spec.rb new file mode 100644 index 00000000000..935f833fa8b --- /dev/null +++ b/spec/tooling/lib/tooling/mappings/base_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require_relative '../../../../../tooling/lib/tooling/mappings/view_to_js_mappings' + +RSpec.describe Tooling::Mappings::Base, feature_category: :tooling do + describe '#folders_for_available_editions' do + let(:base_folder_path) { 'app/views' } + + subject { described_class.new.folders_for_available_editions(base_folder_path) } + + context 'when FOSS' do + before do + allow(GitlabEdition).to receive(:ee?).and_return(false) + allow(GitlabEdition).to receive(:jh?).and_return(false) + end + + it 'returns the correct paths' do + expect(subject).to match_array([base_folder_path]) + end + end + + context 'when EE' do + before do + allow(GitlabEdition).to receive(:ee?).and_return(true) + allow(GitlabEdition).to receive(:jh?).and_return(false) + end + + it 'returns the correct paths' do + expect(subject).to match_array([base_folder_path, "ee/#{base_folder_path}"]) + end + end + + context 'when JiHu' do + before do + allow(GitlabEdition).to receive(:ee?).and_return(true) + allow(GitlabEdition).to receive(:jh?).and_return(true) + end + + it 'returns the correct paths' do + expect(subject).to match_array([base_folder_path, "ee/#{base_folder_path}", "jh/#{base_folder_path}"]) + end + end + end +end diff --git a/spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb b/spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb new file mode 100644 index 00000000000..72e02547938 --- /dev/null +++ b/spec/tooling/lib/tooling/mappings/js_to_system_specs_mappings_spec.rb @@ -0,0 +1,169 @@ +# frozen_string_literal: true + +require 'tempfile' +require_relative '../../../../../tooling/lib/tooling/mappings/js_to_system_specs_mappings' + +RSpec.describe Tooling::Mappings::JsToSystemSpecsMappings, feature_category: :tooling do + # We set temporary folders, and those readers give access to those folder paths + attr_accessor :js_base_folder, :system_specs_base_folder + + around do |example| + Dir.mktmpdir do |tmp_js_base_folder| + Dir.mktmpdir do |tmp_system_specs_base_folder| + self.system_specs_base_folder = tmp_system_specs_base_folder + self.js_base_folder = tmp_js_base_folder + + example.run + end + end + end + + describe '#execute' do + let(:instance) do + described_class.new( + system_specs_base_folder: system_specs_base_folder, + js_base_folder: js_base_folder + ) + end + + subject { instance.execute(changed_files) } + + context 'when no JS files were changed' do + let(:changed_files) { [] } + + it 'returns nothing' do + expect(subject).to match_array([]) + end + end + + context 'when some JS files were changed' do + let(:changed_files) { ["#{js_base_folder}/issues/secret_values.js"] } + + context 'when the JS files are not present on disk' do + it 'returns nothing' do + expect(subject).to match_array([]) + end + end + + context 'when the JS files are present on disk' do + before do + FileUtils.mkdir_p("#{js_base_folder}/issues") + File.write("#{js_base_folder}/issues/secret_values.js", "hello") + end + + context 'when no system specs match the JS keyword' do + it 'returns nothing' do + expect(subject).to match_array([]) + end + end + + context 'when a system spec matches the JS keyword' do + before do + FileUtils.mkdir_p("#{system_specs_base_folder}/confidential_issues") + File.write("#{system_specs_base_folder}/confidential_issues/issues_spec.rb", "a test") + end + + it 'returns something' do + expect(subject).to match_array(["#{system_specs_base_folder}/confidential_issues/issues_spec.rb"]) + end + end + end + end + end + + describe '#filter_files' do + subject { described_class.new(js_base_folder: js_base_folder).filter_files(changed_files) } + + before do + File.write("#{js_base_folder}/index.js", "index.js") + File.write("#{js_base_folder}/index-with-ee-in-it.js", "index-with-ee-in-it.js") + File.write("#{js_base_folder}/index-with-jh-in-it.js", "index-with-jh-in-it.js") + end + + context 'when no files were changed' do + let(:changed_files) { [] } + + it 'returns an empty array' do + expect(subject).to match_array([]) + end + end + + context 'when JS files were changed' do + let(:changed_files) do + [ + "#{js_base_folder}/index.js", + "#{js_base_folder}/index-with-ee-in-it.js", + "#{js_base_folder}/index-with-jh-in-it.js" + ] + end + + it 'returns the path to the JS files' do + # "nil" group represents FOSS JS files in app/assets/javascripts + expect(subject).to match(nil => [ + "#{js_base_folder}/index.js", + "#{js_base_folder}/index-with-ee-in-it.js", + "#{js_base_folder}/index-with-jh-in-it.js" + ]) + end + end + + context 'when JS files are deleted' do + let(:changed_files) { ["#{system_specs_base_folder}/deleted.html"] } + + it 'returns an empty array' do + expect(subject).to match_array([]) + end + end + end + + describe '#construct_js_keywords' do + subject { described_class.new.construct_js_keywords(js_files) } + + let(:js_files) do + %w[ + app/assets/javascripts/boards/issue_board_filters.js + ee/app/assets/javascripts/queries/epic_due_date.query.graphql + ] + end + + it 'returns a singularized keyword based on the first folder the file is in' do + expect(subject).to eq(%w[board query]) + end + end + + describe '#system_specs_for_edition' do + subject do + described_class.new(system_specs_base_folder: system_specs_base_folder).system_specs_for_edition(edition) + end + + context 'when FOSS' do + let(:edition) { nil } + + it 'checks the correct folder' do + expect(Dir).to receive(:[]).with("#{system_specs_base_folder}/**/*").and_call_original + + subject + end + end + + context 'when EE' do + let(:edition) { 'ee' } + + it 'checks the correct folder' do + expect(Dir).to receive(:[]).with("ee#{system_specs_base_folder}/**/*").and_call_original + + subject + end + end + + context 'when JiHu' do + let(:edition) { 'jh' } + + it 'checks the correct folder' do + expect(Dir).to receive(:[]).with("jh#{system_specs_base_folder}/**/*").and_call_original + + subject + end + end + end +end diff --git a/spec/tooling/lib/tooling/view_to_js_mappings_spec.rb b/spec/tooling/lib/tooling/mappings/view_to_js_mappings_spec.rb index b09df2a9200..eaa0124370d 100644 --- a/spec/tooling/lib/tooling/view_to_js_mappings_spec.rb +++ b/spec/tooling/lib/tooling/mappings/view_to_js_mappings_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true require 'tempfile' -require_relative '../../../../tooling/lib/tooling/view_to_js_mappings' +require_relative '../../../../../tooling/lib/tooling/mappings/view_to_js_mappings' -RSpec.describe Tooling::ViewToJsMappings, feature_category: :tooling do +RSpec.describe Tooling::Mappings::ViewToJsMappings, feature_category: :tooling do # We set temporary folders, and those readers give access to those folder paths attr_accessor :view_base_folder, :js_base_folder @@ -32,7 +32,7 @@ RSpec.describe Tooling::ViewToJsMappings, feature_category: :tooling do context 'when no view files have been changed' do before do - allow(instance).to receive(:view_files).and_return([]) + allow(instance).to receive(:filter_files).and_return([]) end it 'returns nothing' do @@ -140,8 +140,8 @@ RSpec.describe Tooling::ViewToJsMappings, feature_category: :tooling do end end - describe '#view_files' do - subject { described_class.new(view_base_folder: view_base_folder).view_files(changed_files) } + describe '#filter_files' do + subject { described_class.new(view_base_folder: view_base_folder).filter_files(changed_files) } before do File.write("#{js_base_folder}/index.js", "index.js") @@ -181,45 +181,6 @@ RSpec.describe Tooling::ViewToJsMappings, feature_category: :tooling do end end - describe '#folders_for_available_editions' do - let(:base_folder_path) { 'app/views' } - - subject { described_class.new.folders_for_available_editions(base_folder_path) } - - context 'when FOSS' do - before do - allow(GitlabEdition).to receive(:ee?).and_return(false) - allow(GitlabEdition).to receive(:jh?).and_return(false) - end - - it 'returns the correct paths' do - expect(subject).to match_array([base_folder_path]) - end - end - - context 'when EE' do - before do - allow(GitlabEdition).to receive(:ee?).and_return(true) - allow(GitlabEdition).to receive(:jh?).and_return(false) - end - - it 'returns the correct paths' do - expect(subject).to eq([base_folder_path, "ee/#{base_folder_path}"]) - end - end - - context 'when JiHu' do - before do - allow(GitlabEdition).to receive(:ee?).and_return(true) - allow(GitlabEdition).to receive(:jh?).and_return(true) - end - - it 'returns the correct paths' do - expect(subject).to eq([base_folder_path, "ee/#{base_folder_path}", "jh/#{base_folder_path}"]) - end - end - end - describe '#find_partials' do subject { described_class.new(view_base_folder: view_base_folder).find_partials(file_path) } |