Commit aa4ec037 authored by allison.browne's avatar allison.browne Committed by Ash McKenzie

Changes based on Code Review

Add specs for GitLab staging helper
Add a new helper method, other cleanup.
parent cb5938d2
......@@ -5283,7 +5283,8 @@ CREATE TABLE public.project_settings (
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
push_rule_id bigint,
show_default_award_emojis boolean DEFAULT true NOT NULL
show_default_award_emojis boolean DEFAULT true,
CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL))
);
CREATE TABLE public.project_statistics (
......
......@@ -35,8 +35,8 @@ module Gitlab
end
end
STAGING_COM_URL = 'https://staging.gitlab.com'
COM_URL = 'https://gitlab.com'
STAGING_COM_URL = 'https://staging.gitlab.com'
APP_DIRS_PATTERN = %r{^/?(app|config|ee|lib|spec|\(\w*\))}.freeze
SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}.freeze
VERSION = File.read(root.join("VERSION")).strip.freeze
......@@ -80,6 +80,10 @@ module Gitlab
Rails.env.development? || com?
end
def self.dev_or_test_env?
Rails.env.development? || Rails.env.test?
end
def self.ee?
@is_ee ||=
# We use this method when the Rails environment is not loaded. This
......
......@@ -2,18 +2,25 @@
module Gitlab
module Monitor
# See Demo Project documentation
# https://about.gitlab.com/handbook/engineering/development/ops/monitor/#demo-environments
module DemoProjects
# [https://gitlab.com/gitlab-org/monitor/tanuki-inc, https://gitlab.com/gitlab-org/monitor/monitor-sandbox]
DOT_COM_IDS = [14986497, 12507547].freeze
# [https://staging.gitlab.com/gitlab-org/monitor/monitor-sandbox]
STAGING_IDS = [4422333].freeze
def self.primary_keys
if ::Gitlab.com?
# .com? returns true for staging
if ::Gitlab.com? && !::Gitlab.staging?
DOT_COM_IDS
elsif ::Gitlab.staging?
STAGING_IDS
elsif Rails.env.development? || Rails.env.test?
elsif ::Gitlab.dev_or_test_env?
Project.pluck(:id) # rubocop: disable CodeReuse/ActiveRecord
end || []
else
[]
end
end
end
end
......
......@@ -6,29 +6,30 @@ describe Gitlab::Monitor::DemoProjects do
describe '#primary_keys' do
subject { described_class.primary_keys }
it 'fetches primary_keys when in test env' do
project = create(:project)
expect(subject).to eq([project.id])
end
it 'fetches primary_keys when on gitlab.com' do
expect(Gitlab).to receive(:'com?').and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
allow(Gitlab).to receive(:staging?).and_return(false)
expect(subject).to eq(Gitlab::Monitor::DemoProjects::DOT_COM_IDS)
end
it 'fetches primary_keys when on staging' do
expect(Gitlab).to receive(:staging?).and_return(true)
allow(Gitlab).to receive(:com?).and_return(true)
allow(Gitlab).to receive(:staging?).and_return(true)
expect(subject).to eq(Gitlab::Monitor::DemoProjects::STAGING_IDS)
end
it 'fetches all keys when in the dev or test env' do
project = create(:project)
allow(Gitlab).to receive(:dev_or_test_env?).and_return(true)
expect(subject).to eq([project.id])
end
it 'falls back on empty array' do
stub_config_setting(url: 'https://helloworld')
expect(Rails).to receive(:env).and_return(
double(development?: false, test?: false)
).twice
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
expect(subject).to eq([])
end
......
......@@ -96,6 +96,28 @@ describe Gitlab do
end
end
describe '.staging?' do
subject { described_class.staging? }
it 'is false when on GitLab.com' do
stub_config_setting(url: 'https://gitlab.com')
expect(subject).to eq false
end
it 'is true when on staging' do
stub_config_setting(url: 'https://staging.gitlab.com')
expect(subject).to eq true
end
it 'is flase when not on staging' do
stub_config_setting(url: 'https://example.gitlab.com')
expect(subject).to eq false
end
end
describe '.canary?' do
it 'is true when CANARY env var is set to true' do
stub_env('CANARY', '1')
......@@ -186,6 +208,27 @@ describe Gitlab do
end
end
describe '.dev_or_test_env?' do
subject { described_class.dev_or_test_env? }
it 'is true when test env' do
expect(subject).to eq true
end
it 'is true when dev env' do
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development'))
expect(subject).to eq true
end
it 'is false when env is not dev or test' do
allow(described_class).to receive(:com?).and_return(false)
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production'))
expect(subject).to eq false
end
end
describe '.ee?' do
before do
stub_env('FOSS_ONLY', nil) # Make sure the ENV is clean
......
......@@ -8,7 +8,7 @@ describe Clusters::Applications::CheckPrometheusHealthWorker, '#perform' do
it 'triggers health service' do
cluster = create(:cluster)
allow(Gitlab::Monitor::DemoProjects).to receive(:primary_keys)
allow(Clusters::Cluster).to receive(:with_application_prometheus).and_return(double(with_project_alert_service_data: [cluster]))
allow(Clusters::Cluster).to receive_message_chain(:with_application_prometheus, :with_project_alert_service_data).and_return([cluster])
service_instance = instance_double(Clusters::Applications::PrometheusHealthCheckService)
expect(Clusters::Applications::PrometheusHealthCheckService).to receive(:new).with(cluster).and_return(service_instance)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment