summaryrefslogtreecommitdiff
path: root/spec/models/clusters/cluster_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/clusters/cluster_spec.rb')
-rw-r--r--spec/models/clusters/cluster_spec.rb76
1 files changed, 75 insertions, 1 deletions
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb
index a8f81cba285..b2ed64fd9b0 100644
--- a/spec/models/clusters/cluster_spec.rb
+++ b/spec/models/clusters/cluster_spec.rb
@@ -21,6 +21,7 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to have_one(:provider_gcp) }
it { is_expected.to have_one(:provider_aws) }
it { is_expected.to have_one(:platform_kubernetes) }
+ it { is_expected.to have_one(:integration_prometheus) }
it { is_expected.to have_one(:application_helm) }
it { is_expected.to have_one(:application_ingress) }
it { is_expected.to have_one(:application_prometheus) }
@@ -40,7 +41,6 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to delegate_method(:rbac?).to(:platform_kubernetes).with_prefix }
it { is_expected.to delegate_method(:available?).to(:application_helm).with_prefix }
it { is_expected.to delegate_method(:available?).to(:application_ingress).with_prefix }
- it { is_expected.to delegate_method(:available?).to(:application_prometheus).with_prefix }
it { is_expected.to delegate_method(:available?).to(:application_knative).with_prefix }
it { is_expected.to delegate_method(:available?).to(:application_elastic_stack).with_prefix }
it { is_expected.to delegate_method(:external_ip).to(:application_ingress).with_prefix }
@@ -1349,6 +1349,80 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end
end
+ describe '#application_prometheus_available?' do
+ let_it_be_with_reload(:cluster) { create(:cluster, :project) }
+
+ subject { cluster.application_prometheus_available? }
+
+ it { is_expected.to be_falsey }
+
+ context 'has a integration_prometheus' do
+ let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
+
+ it { is_expected.to be_truthy }
+
+ context 'disabled' do
+ before do
+ cluster.integration_prometheus.enabled = false
+ end
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ context 'has a application_prometheus' do
+ let_it_be(:application) { create(:clusters_applications_prometheus, :installed, :no_helm_installed, cluster: cluster) }
+
+ it { is_expected.to be_truthy }
+
+ context 'errored' do
+ before do
+ cluster.application_prometheus.status = Clusters::Applications::Prometheus.state_machines[:status].states[:errored]
+ end
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'also has a integration_prometheus' do
+ let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+ end
+
+ describe '#prometheus_adapter' do
+ let_it_be_with_reload(:cluster) { create(:cluster, :project) }
+
+ it 'returns nothing' do
+ expect(cluster.prometheus_adapter).to be_nil
+ end
+
+ context 'has a integration_prometheus' do
+ let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
+
+ it 'returns the integration' do
+ expect(cluster.prometheus_adapter).to eq(integration)
+ end
+ end
+
+ context 'has a application_prometheus' do
+ let_it_be(:application) { create(:clusters_applications_prometheus, :no_helm_installed, cluster: cluster) }
+
+ it 'returns the application' do
+ expect(cluster.prometheus_adapter).to eq(application)
+ end
+
+ context 'also has a integration_prometheus' do
+ let_it_be(:integration) { create(:clusters_integrations_prometheus, cluster: cluster) }
+
+ it 'returns the integration' do
+ expect(cluster.prometheus_adapter).to eq(integration)
+ end
+ end
+ end
+ end
+
describe '#delete_cached_resources!' do
let!(:cluster) { create(:cluster, :project) }
let!(:staging_namespace) { create(:cluster_kubernetes_namespace, cluster: cluster, namespace: 'staging') }