2021-05-19 20:10:36 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'gitlab-dangerfiles'
|
|
|
|
require 'gitlab/dangerfiles/spec_helper'
|
|
|
|
|
|
|
|
require_relative '../../../tooling/danger/product_intelligence'
|
|
|
|
require_relative '../../../tooling/danger/project_helper'
|
|
|
|
|
|
|
|
RSpec.describe Tooling::Danger::ProductIntelligence do
|
|
|
|
include_context "with dangerfile"
|
|
|
|
|
|
|
|
subject(:product_intelligence) { fake_danger.new(helper: fake_helper) }
|
|
|
|
|
|
|
|
let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
|
2021-08-11 05:10:00 -04:00
|
|
|
let(:changed_files) { ['metrics/counts_7d/test_metric.yml'] }
|
2021-05-19 20:10:36 -04:00
|
|
|
let(:changed_lines) { ['+tier: ee'] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(fake_helper).to receive(:all_changed_files).and_return(changed_files)
|
|
|
|
allow(fake_helper).to receive(:changed_lines).and_return(changed_lines)
|
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
describe '#check!' do
|
|
|
|
subject { product_intelligence.check! }
|
2021-05-19 20:10:36 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
let(:markdown_formatted_list) { 'markdown formatted list' }
|
|
|
|
let(:review_pending_label) { 'product intelligence::review pending' }
|
|
|
|
let(:approved_label) { 'product intelligence::approved' }
|
2021-05-19 20:10:36 -04:00
|
|
|
let(:ci_env) { true }
|
2022-03-30 14:08:19 -04:00
|
|
|
let(:previous_label_to_add) { 'label_to_add' }
|
|
|
|
let(:labels_to_add) { [previous_label_to_add] }
|
|
|
|
let(:has_product_intelligence_label) { true }
|
2021-05-19 20:10:36 -04:00
|
|
|
|
|
|
|
before do
|
2022-03-30 14:08:19 -04:00
|
|
|
allow(fake_helper).to receive(:changes_by_category).and_return(product_intelligence: changed_files, database: ['other_files.yml'])
|
2021-05-19 20:10:36 -04:00
|
|
|
allow(fake_helper).to receive(:ci?).and_return(ci_env)
|
2022-03-30 14:08:19 -04:00
|
|
|
allow(fake_helper).to receive(:mr_has_labels?).with('product intelligence').and_return(has_product_intelligence_label)
|
|
|
|
allow(fake_helper).to receive(:markdown_list).with(changed_files).and_return(markdown_formatted_list)
|
|
|
|
allow(fake_helper).to receive(:labels_to_add).and_return(labels_to_add)
|
2021-05-19 20:10:36 -04:00
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
shared_examples "doesn't add new labels" do
|
|
|
|
it "doesn't add new labels" do
|
|
|
|
subject
|
2021-05-19 20:10:36 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
expect(labels_to_add).to match_array [previous_label_to_add]
|
|
|
|
end
|
2021-05-19 20:10:36 -04:00
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
shared_examples "doesn't add new warnings" do
|
|
|
|
it "doesn't add new warnings" do
|
|
|
|
expect(product_intelligence).not_to receive(:warn)
|
2021-05-19 20:10:36 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
subject
|
|
|
|
end
|
2021-05-19 20:10:36 -04:00
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
shared_examples 'adds new labels' do
|
|
|
|
it 'adds new labels' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(labels_to_add).to match_array [previous_label_to_add, review_pending_label]
|
|
|
|
end
|
|
|
|
end
|
2021-05-19 20:10:36 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
context 'with growth experiment label' do
|
2021-05-19 20:10:36 -04:00
|
|
|
before do
|
2022-03-30 14:08:19 -04:00
|
|
|
allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(true)
|
2021-05-19 20:10:36 -04:00
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
include_examples "doesn't add new labels"
|
|
|
|
include_examples "doesn't add new warnings"
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without growth experiment label' do
|
|
|
|
before do
|
|
|
|
allow(fake_helper).to receive(:mr_has_labels?).with('growth experiment').and_return(false)
|
|
|
|
end
|
2021-05-19 20:10:36 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
context 'with approved label' do
|
|
|
|
let(:mr_labels) { [approved_label] }
|
2021-10-27 05:12:12 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
include_examples "doesn't add new labels"
|
|
|
|
include_examples "doesn't add new warnings"
|
2021-05-19 20:10:36 -04:00
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
context 'without approved label' do
|
|
|
|
include_examples 'adds new labels'
|
|
|
|
|
|
|
|
it 'warns with proper message' do
|
|
|
|
expect(product_intelligence).to receive(:warn).with(%r{#{markdown_formatted_list}})
|
2021-10-27 05:12:12 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
subject
|
|
|
|
end
|
2021-10-27 05:12:12 -04:00
|
|
|
end
|
2021-12-15 10:15:54 -05:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
context 'with product intelligence::review pending label' do
|
|
|
|
let(:mr_labels) { ['product intelligence::review pending'] }
|
2021-09-27 14:12:38 -04:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
include_examples "doesn't add new labels"
|
2021-09-27 14:12:38 -04:00
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
context 'with product intelligence::approved label' do
|
|
|
|
let(:mr_labels) { ['product intelligence::approved'] }
|
2021-12-15 10:15:54 -05:00
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
include_examples "doesn't add new labels"
|
2021-12-15 10:15:54 -05:00
|
|
|
end
|
|
|
|
|
2022-03-30 14:08:19 -04:00
|
|
|
context 'with the product intelligence label' do
|
|
|
|
let(:has_product_intelligence_label) { true }
|
|
|
|
|
|
|
|
context 'with ci? false' do
|
|
|
|
let(:ci_env) { false }
|
|
|
|
|
|
|
|
include_examples "doesn't add new labels"
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with ci? true' do
|
|
|
|
include_examples 'adds new labels'
|
|
|
|
end
|
|
|
|
end
|
2021-09-27 14:12:38 -04:00
|
|
|
end
|
2021-05-19 20:10:36 -04:00
|
|
|
end
|
|
|
|
end
|