diff options
Diffstat (limited to 'spec/models/clusters/cluster_spec.rb')
-rw-r--r-- | spec/models/clusters/cluster_spec.rb | 78 |
1 files changed, 62 insertions, 16 deletions
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index abef586d258..92ce2b0999a 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -516,29 +516,75 @@ describe Clusters::Cluster do end end - describe '#has_domain?' do - subject { cluster.has_domain? } - - context 'with domain set at instance level' do - let(:cluster) { create(:cluster, :provided_by_gcp) } - - before do - stub_application_setting(auto_devops_domain: 'global_domain.com') - end + describe '#kube_ingress_domain' do + let(:cluster) { create(:cluster, :provided_by_gcp) } - it { is_expected.to be_truthy } - end + subject { cluster.kube_ingress_domain } context 'with domain set in cluster' do let(:cluster) { create(:cluster, :provided_by_gcp, :with_domain) } - it { is_expected.to be_truthy } + it { is_expected.to eq(cluster.domain) } end - context 'when domain is not set at instance level nor in cluster' do - let(:cluster) { create(:cluster, :provided_by_gcp) } + context 'with no domain on cluster' do + context 'with a project cluster' do + let(:cluster) { create(:cluster, :project, :provided_by_gcp) } + let(:project) { cluster.project } + + context 'with domain set at instance level' do + before do + stub_application_setting(auto_devops_domain: 'global_domain.com') + + it { is_expected.to eq('global_domain.com') } + end + end + + context 'with domain set on ProjectAutoDevops' do + before do + auto_devops = project.build_auto_devops(domain: 'legacy-ado-domain.com') + auto_devops.save + end + + it { is_expected.to eq('legacy-ado-domain.com') } + end - it { is_expected.to be_falsy } + context 'with domain set as environment variable on project' do + before do + variable = project.variables.build(key: 'AUTO_DEVOPS_DOMAIN', value: 'project-ado-domain.com') + variable.save + end + + it { is_expected.to eq('project-ado-domain.com') } + end + + context 'with domain set as environment variable on the group project' do + let(:group) { create(:group) } + + before do + project.update(parent_id: group.id) + variable = group.variables.build(key: 'AUTO_DEVOPS_DOMAIN', value: 'group-ado-domain.com') + variable.save + end + + it { is_expected.to eq('group-ado-domain.com') } + end + end + + context 'with a group cluster' do + let(:cluster) { create(:cluster, :group, :provided_by_gcp) } + + context 'with domain set as environment variable for the group' do + let(:group) { cluster.group } + + before do + variable = group.variables.build(key: 'AUTO_DEVOPS_DOMAIN', value: 'group-ado-domain.com') + variable.save + end + + it { is_expected.to eq('group-ado-domain.com') } + end + end end end @@ -566,7 +612,7 @@ describe Clusters::Cluster do end context 'with no domain' do - let(:cluster) { create(:cluster) } + let(:cluster) { create(:cluster, :provided_by_gcp, :project) } it 'should return an empty array' do expect(subject.to_hash).to be_empty |