2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-04 16:32:03 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe ClusterEntity do
|
2020-07-14 11:09:05 -04:00
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
|
2017-10-30 12:03:58 -04:00
|
|
|
describe '#as_json' do
|
2020-07-14 11:09:05 -04:00
|
|
|
let(:user) { nil }
|
|
|
|
let(:request) { EntityRequest.new({ current_user: user }) }
|
|
|
|
|
|
|
|
subject { described_class.new(cluster, request: request).as_json }
|
2017-10-04 16:32:03 -04:00
|
|
|
|
2017-10-30 12:03:58 -04:00
|
|
|
context 'when provider type is gcp' do
|
2020-04-30 17:09:47 -04:00
|
|
|
let(:cluster) { create(:cluster, :instance, provider_type: :gcp, provider_gcp: provider) }
|
2017-10-04 16:32:03 -04:00
|
|
|
|
2017-10-30 12:03:58 -04:00
|
|
|
context 'when status is creating' do
|
2017-11-06 09:06:10 -05:00
|
|
|
let(:provider) { create(:cluster_provider_gcp, :creating) }
|
2017-10-04 16:32:03 -04:00
|
|
|
|
2017-10-30 12:03:58 -04:00
|
|
|
it 'has corresponded data' do
|
|
|
|
expect(subject[:status]).to eq(:creating)
|
|
|
|
expect(subject[:status_reason]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when status is errored' do
|
2017-11-06 09:06:10 -05:00
|
|
|
let(:provider) { create(:cluster_provider_gcp, :errored) }
|
2017-10-30 12:03:58 -04:00
|
|
|
|
|
|
|
it 'has corresponded data' do
|
|
|
|
expect(subject[:status]).to eq(:errored)
|
|
|
|
expect(subject[:status_reason]).to eq(provider.status_reason)
|
|
|
|
end
|
|
|
|
end
|
2017-10-04 16:32:03 -04:00
|
|
|
end
|
|
|
|
|
2017-10-30 12:03:58 -04:00
|
|
|
context 'when provider type is user' do
|
2020-04-30 17:09:47 -04:00
|
|
|
let(:cluster) { create(:cluster, :instance, provider_type: :user) }
|
2017-10-30 12:03:58 -04:00
|
|
|
|
2017-11-07 03:02:50 -05:00
|
|
|
it 'has corresponded data' do
|
|
|
|
expect(subject[:status]).to eq(:created)
|
2017-10-30 12:03:58 -04:00
|
|
|
expect(subject[:status_reason]).to be_nil
|
|
|
|
end
|
2017-10-04 16:32:03 -04:00
|
|
|
end
|
2017-10-31 06:29:56 -04:00
|
|
|
|
2017-11-06 11:02:28 -05:00
|
|
|
context 'when no application has been installed' do
|
2020-04-30 17:09:47 -04:00
|
|
|
let(:cluster) { create(:cluster, :instance) }
|
2019-12-17 13:07:48 -05:00
|
|
|
|
2020-07-14 11:09:05 -04:00
|
|
|
subject { described_class.new(cluster, request: request).as_json[:applications]}
|
2017-11-06 11:02:28 -05:00
|
|
|
|
2017-11-07 11:32:12 -05:00
|
|
|
it 'contains helm as not_installable' do
|
2017-11-06 11:02:28 -05:00
|
|
|
expect(subject).not_to be_empty
|
|
|
|
|
|
|
|
helm = subject[0]
|
|
|
|
expect(helm[:name]).to eq('helm')
|
2017-11-07 11:32:12 -05:00
|
|
|
expect(helm[:status]).to eq(:not_installable)
|
2017-11-06 11:02:28 -05:00
|
|
|
end
|
2017-10-31 06:29:56 -04:00
|
|
|
end
|
2020-07-14 11:09:05 -04:00
|
|
|
|
|
|
|
context 'gitlab_managed_apps_logs_path' do
|
|
|
|
let(:cluster) { create(:cluster, :project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { described_class.new(cluster, request: request).as_json }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Clusters::ClusterPresenter) do |presenter|
|
|
|
|
allow(presenter).to receive(:show_path).and_return(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'return projects log explorer path' do
|
|
|
|
log_explorer_path = project_logs_path(cluster.project, cluster_id: cluster.id)
|
|
|
|
|
|
|
|
expect_next_instance_of(Clusters::ClusterPresenter, cluster, current_user: user) do |presenter|
|
|
|
|
expect(presenter).to receive(:gitlab_managed_apps_logs_path).and_return(log_explorer_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(subject[:gitlab_managed_apps_logs_path]).to eq(log_explorer_path)
|
|
|
|
end
|
|
|
|
end
|
2020-08-26 14:11:43 -04:00
|
|
|
|
|
|
|
context 'enable_advanced_logs_querying' do
|
|
|
|
let(:cluster) { create(:cluster, :project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { described_class.new(cluster, request: request).as_json }
|
|
|
|
|
|
|
|
context 'elastic stack is not installed on cluster' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject[:enable_advanced_logs_querying]).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-03 08:10:18 -04:00
|
|
|
context 'elastic stack is enabled on cluster' do
|
2020-08-26 14:11:43 -04:00
|
|
|
it 'returns true' do
|
2021-06-03 08:10:18 -04:00
|
|
|
create(:clusters_integrations_elastic_stack, cluster: cluster)
|
2020-08-26 14:11:43 -04:00
|
|
|
|
|
|
|
expect(subject[:enable_advanced_logs_querying]).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-10-04 16:32:03 -04:00
|
|
|
end
|
|
|
|
end
|