summaryrefslogtreecommitdiff
path: root/spec/models/clusters/applications/prometheus_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/clusters/applications/prometheus_spec.rb')
-rw-r--r--spec/models/clusters/applications/prometheus_spec.rb100
1 files changed, 66 insertions, 34 deletions
diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb
index 2aeb7e5a990..d588ce3bc38 100644
--- a/spec/models/clusters/applications/prometheus_spec.rb
+++ b/spec/models/clusters/applications/prometheus_spec.rb
@@ -12,35 +12,29 @@ describe Clusters::Applications::Prometheus do
include_examples 'cluster application initial status specs'
describe 'after_destroy' do
- let(:project) { create(:project) }
- let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) }
- let!(:application) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
- let!(:prometheus_service) { project.create_prometheus_service(active: true) }
+ context 'cluster type is project' do
+ let(:cluster) { create(:cluster, :with_installed_helm) }
+ let(:application) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
- it 'deactivates prometheus_service after destroy' do
- expect do
- application.destroy!
+ it 'deactivates prometheus_service after destroy' do
+ expect(Clusters::Applications::DeactivateServiceWorker)
+ .to receive(:perform_async).with(cluster.id, 'prometheus')
- prometheus_service.reload
- end.to change(prometheus_service, :active).from(true).to(false)
+ application.destroy!
+ end
end
end
describe 'transition to installed' do
let(:project) { create(:project) }
- let(:cluster) { create(:cluster, :with_installed_helm, projects: [project]) }
- let(:prometheus_service) { double('prometheus_service') }
+ let(:cluster) { create(:cluster, :with_installed_helm) }
+ let(:application) { create(:clusters_applications_prometheus, :installing, cluster: cluster) }
- subject { create(:clusters_applications_prometheus, :installing, cluster: cluster) }
+ it 'schedules post installation job' do
+ expect(Clusters::Applications::ActivateServiceWorker)
+ .to receive(:perform_async).with(cluster.id, 'prometheus')
- before do
- allow(project).to receive(:find_or_initialize_service).with('prometheus').and_return prometheus_service
- end
-
- it 'ensures Prometheus service is activated' do
- expect(prometheus_service).to receive(:update!).with(active: true)
-
- subject.make_installed
+ application.make_installed
end
end
@@ -53,6 +47,16 @@ describe Clusters::Applications::Prometheus do
end
describe '#prometheus_client' do
+ shared_examples 'exception caught for prometheus client' do
+ before do
+ allow(kube_client).to receive(:proxy_url).and_raise(exception)
+ end
+
+ it 'returns nil' do
+ expect(subject.prometheus_client).to be_nil
+ end
+ end
+
context 'cluster is nil' do
it 'returns nil' do
expect(subject.cluster).to be_nil
@@ -98,12 +102,18 @@ describe Clusters::Applications::Prometheus do
end
context 'when cluster is not reachable' do
- before do
- allow(kube_client).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil))
+ it_behaves_like 'exception caught for prometheus client' do
+ let(:exception) { Kubeclient::HttpError.new(401, 'Unauthorized', nil) }
+ end
+ end
+
+ context 'when there is a socket error while contacting cluster' do
+ it_behaves_like 'exception caught for prometheus client' do
+ let(:exception) { Errno::ECONNREFUSED }
end
- it 'returns nil' do
- expect(subject.prometheus_client).to be_nil
+ it_behaves_like 'exception caught for prometheus client' do
+ let(:exception) { Errno::ECONNRESET }
end
end
end
@@ -196,21 +206,19 @@ describe Clusters::Applications::Prometheus do
end
end
- describe '#upgrade_command' do
+ describe '#patch_command' do
+ subject(:patch_command) { prometheus.patch_command(values) }
+
let(:prometheus) { build(:clusters_applications_prometheus) }
let(:values) { prometheus.values }
- it 'returns an instance of Gitlab::Kubernetes::Helm::InstallCommand' do
- expect(prometheus.upgrade_command(values)).to be_an_instance_of(::Gitlab::Kubernetes::Helm::InstallCommand)
- end
+ it { is_expected.to be_an_instance_of(::Gitlab::Kubernetes::Helm::PatchCommand) }
it 'is initialized with 3 arguments' do
- command = prometheus.upgrade_command(values)
-
- expect(command.name).to eq('prometheus')
- expect(command.chart).to eq('stable/prometheus')
- expect(command.version).to eq('6.7.3')
- expect(command.files).to eq(prometheus.files)
+ expect(patch_command.name).to eq('prometheus')
+ expect(patch_command.chart).to eq('stable/prometheus')
+ expect(patch_command.version).to eq('6.7.3')
+ expect(patch_command.files).to eq(prometheus.files)
end
end
@@ -289,4 +297,28 @@ describe Clusters::Applications::Prometheus do
end
end
end
+
+ describe '#configured?' do
+ let(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
+
+ subject { prometheus.configured? }
+
+ context 'when a kubenetes client is present' do
+ let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+
+ it { is_expected.to be_truthy }
+
+ context 'when it is not availalble' do
+ let(:prometheus) { create(:clusters_applications_prometheus, cluster: cluster) }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ context 'when a kubenetes client is not present' do
+ let(:cluster) { create(:cluster) }
+
+ it { is_expected.to be_falsy }
+ end
+ end
end