diff options
Diffstat (limited to 'spec')
18 files changed, 379 insertions, 202 deletions
diff --git a/spec/controllers/projects/serverless/functions_controller_spec.rb b/spec/controllers/projects/serverless/functions_controller_spec.rb index db7533eb609..203e1e49994 100644 --- a/spec/controllers/projects/serverless/functions_controller_spec.rb +++ b/spec/controllers/projects/serverless/functions_controller_spec.rb @@ -135,7 +135,7 @@ describe Projects::Serverless::FunctionsController do context 'when there is no serverless domain for a cluster' do it 'keeps function URL as it was' do - expect(Gitlab::Serverless::Domain).not_to receive(:new) + expect(::Serverless::Domain).not_to receive(:new) get :index, params: params({ format: :json }) expect(response).to have_gitlab_http_status(:ok) diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb index ff9fc882dcc..0a4f0fba9ab 100644 --- a/spec/factories/clusters/applications/helm.rb +++ b/spec/factories/clusters/applications/helm.rb @@ -73,39 +73,71 @@ FactoryBot.define do factory :clusters_applications_ingress, class: 'Clusters::Applications::Ingress' do modsecurity_enabled { false } cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end factory :clusters_applications_cert_manager, class: 'Clusters::Applications::CertManager' do email { 'admin@example.com' } cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end factory :clusters_applications_elastic_stack, class: 'Clusters::Applications::ElasticStack' do cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end factory :clusters_applications_crossplane, class: 'Clusters::Applications::Crossplane' do stack { 'gcp' } cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end factory :clusters_applications_prometheus, class: 'Clusters::Applications::Prometheus' do cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end factory :clusters_applications_runner, class: 'Clusters::Applications::Runner' do runner factory: %i(ci_runner) cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end factory :clusters_applications_knative, class: 'Clusters::Applications::Knative' do hostname { 'example.com' } cluster factory: %i(cluster with_installed_helm provided_by_gcp) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end factory :clusters_applications_jupyter, class: 'Clusters::Applications::Jupyter' do oauth_application factory: :oauth_application cluster factory: %i(cluster with_installed_helm provided_by_gcp project) + + trait :no_helm_installed do + cluster factory: %i(cluster provided_by_gcp) + end end end end diff --git a/spec/factories/serverless/domain.rb b/spec/factories/serverless/domain.rb new file mode 100644 index 00000000000..7a6a048fb34 --- /dev/null +++ b/spec/factories/serverless/domain.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :serverless_domain, class: '::Serverless::Domain' do + function_name { 'test-function' } + serverless_domain_cluster { create(:serverless_domain_cluster) } + environment { create(:environment) } + + skip_create + end +end diff --git a/spec/finders/serverless_domain_finder_spec.rb b/spec/finders/serverless_domain_finder_spec.rb new file mode 100644 index 00000000000..3fe82264cda --- /dev/null +++ b/spec/finders/serverless_domain_finder_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ServerlessDomainFinder do + let(:function_name) { 'test-function' } + let(:pages_domain_name) { 'serverless.gitlab.io' } + let(:pages_domain) { create(:pages_domain, :instance_serverless, domain: pages_domain_name) } + let!(:serverless_domain_cluster) { create(:serverless_domain_cluster, uuid: 'abcdef12345678', pages_domain: pages_domain) } + let(:valid_cluster_uuid) { 'aba1cdef123456f278' } + let(:invalid_cluster_uuid) { 'aba1cdef123456f178' } + let!(:environment) { create(:environment, name: 'test') } + + let(:valid_uri) { "https://#{function_name}-#{valid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" } + let(:valid_fqdn) { "#{function_name}-#{valid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" } + let(:invalid_uri) { "https://#{function_name}-#{invalid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" } + + let(:valid_finder) { described_class.new(valid_uri) } + let(:invalid_finder) { described_class.new(invalid_uri) } + + describe '#serverless?' do + context 'with a valid URI' do + subject { valid_finder.serverless? } + + it { is_expected.to be_truthy } + end + + context 'with an invalid URI' do + subject { invalid_finder.serverless? } + + it { is_expected.to be_falsy } + end + end + + describe '#serverless_domain_cluster_uuid' do + context 'with a valid URI' do + subject { valid_finder.serverless_domain_cluster_uuid } + + it { is_expected.to eq serverless_domain_cluster.uuid } + end + + context 'with an invalid URI' do + subject { invalid_finder.serverless_domain_cluster_uuid } + + it { is_expected.to be_nil } + end + end + + describe '#execute' do + context 'with a valid URI' do + let(:serverless_domain) do + create( + :serverless_domain, + function_name: function_name, + serverless_domain_cluster: serverless_domain_cluster, + environment: environment + ) + end + + subject { valid_finder.execute } + + it 'has the correct function_name' do + expect(subject.function_name).to eq function_name + end + + it 'has the correct serverless_domain_cluster' do + expect(subject.serverless_domain_cluster).to eq serverless_domain_cluster + end + + it 'has the correct environment' do + expect(subject.environment).to eq environment + end + end + + context 'with an invalid URI' do + subject { invalid_finder.execute } + + it { is_expected.to be_nil } + end + end +end diff --git a/spec/frontend/monitoring/components/charts/anomaly_spec.js b/spec/frontend/monitoring/components/charts/anomaly_spec.js index cea22d075ec..e2d001c3058 100644 --- a/spec/frontend/monitoring/components/charts/anomaly_spec.js +++ b/spec/frontend/monitoring/components/charts/anomaly_spec.js @@ -11,7 +11,6 @@ import { } from '../../mock_data'; import MonitorTimeSeriesChart from '~/monitoring/components/charts/time_series.vue'; -const mockWidgets = 'mockWidgets'; const mockProjectPath = `${TEST_HOST}${mockProjectDir}`; jest.mock('~/lib/utils/icon_utils'); // mock getSvgIconPathContent @@ -35,9 +34,6 @@ describe('Anomaly chart component', () => { const setupAnomalyChart = props => { wrapper = shallowMount(Anomaly, { propsData: { ...props }, - slots: { - default: mockWidgets, - }, }); }; const findTimeSeries = () => wrapper.find(MonitorTimeSeriesChart); diff --git a/spec/frontend/monitoring/components/charts/empty_chart_spec.js b/spec/frontend/monitoring/components/charts/empty_chart_spec.js index bbfca27dc5a..d755ed7c104 100644 --- a/spec/frontend/monitoring/components/charts/empty_chart_spec.js +++ b/spec/frontend/monitoring/components/charts/empty_chart_spec.js @@ -13,14 +13,6 @@ describe('Empty Chart component', () => { }); }); - afterEach(() => { - emptyChart.destroy(); - }); - - it('render the chart title', () => { - expect(emptyChart.find({ ref: 'graphTitle' }).text()).toBe(graphTitle); - }); - describe('Computed props', () => { it('sets the height for the svg container', () => { expect(emptyChart.vm.svgContainerStyle.height).toBe('300px'); diff --git a/spec/frontend/monitoring/components/charts/time_series_spec.js b/spec/frontend/monitoring/components/charts/time_series_spec.js index a911b925b66..49f2a70a8b2 100644 --- a/spec/frontend/monitoring/components/charts/time_series_spec.js +++ b/spec/frontend/monitoring/components/charts/time_series_spec.js @@ -16,8 +16,6 @@ import { } from '../../mock_data'; import * as iconUtils from '~/lib/utils/icon_utils'; -const mockWidgets = 'mockWidgets'; - const mockSvgPathContent = 'mockSvgPathContent'; jest.mock('lodash/throttle', () => @@ -65,9 +63,6 @@ describe('Time series component', () => { deploymentData: store.state.monitoringDashboard.deploymentData, projectPath: `${mockHost}${mockProjectDir}`, }, - slots: { - default: mockWidgets, - }, store, }); }); @@ -82,14 +77,6 @@ describe('Time series component', () => { timeSeriesChart.vm.$nextTick(done); }); - it('renders chart title', () => { - expect(timeSeriesChart.find('.js-graph-title').text()).toBe(mockGraphData.title); - }); - - it('contains graph widgets from slot', () => { - expect(timeSeriesChart.find('.js-graph-widgets').text()).toBe(mockWidgets); - }); - it('allows user to override max value label text using prop', () => { timeSeriesChart.setProps({ legendMaxText: 'legendMaxText' }); diff --git a/spec/frontend/monitoring/components/panel_type_spec.js b/spec/frontend/monitoring/components/panel_type_spec.js index 0d79babf386..dbbe3f55298 100644 --- a/spec/frontend/monitoring/components/panel_type_spec.js +++ b/spec/frontend/monitoring/components/panel_type_spec.js @@ -74,6 +74,18 @@ describe('Panel Type component', () => { glEmptyChart = wrapper.find(EmptyChart); }); + it('renders the chart title', () => { + expect(wrapper.find({ ref: 'graphTitle' }).text()).toBe(graphDataNoResult.title); + }); + + it('renders the no download csv link', () => { + expect(wrapper.find({ ref: 'downloadCsvLink' }).exists()).toBe(false); + }); + + it('does not contain graph widgets', () => { + expect(wrapper.find('.js-graph-widgets').exists()).toBe(false); + }); + it('is a Vue instance', () => { expect(glEmptyChart.isVueInstance()).toBe(true); }); @@ -97,6 +109,15 @@ describe('Panel Type component', () => { wrapper.destroy(); }); + it('renders the chart title', () => { + expect(wrapper.find({ ref: 'graphTitle' }).text()).toBe(graphDataPrometheusQueryRange.title); + }); + + it('contains graph widgets', () => { + expect(wrapper.find('.js-graph-widgets').exists()).toBe(true); + expect(wrapper.find({ ref: 'downloadCsvLink' }).exists()).toBe(true); + }); + it('sets no clipboard copy link on dropdown by default', () => { expect(findCopyLink().exists()).toBe(false); }); diff --git a/spec/frontend/monitoring/shared/prometheus_header_spec.js b/spec/frontend/monitoring/shared/prometheus_header_spec.js deleted file mode 100644 index b216bfb72d8..00000000000 --- a/spec/frontend/monitoring/shared/prometheus_header_spec.js +++ /dev/null @@ -1,26 +0,0 @@ -import { shallowMount } from '@vue/test-utils'; -import PrometheusHeader from '~/monitoring/components/shared/prometheus_header.vue'; - -describe('Prometheus Header component', () => { - let prometheusHeader; - - beforeEach(() => { - prometheusHeader = shallowMount(PrometheusHeader, { - propsData: { - graphTitle: 'graph header', - }, - }); - }); - - afterEach(() => { - prometheusHeader.destroy(); - }); - - describe('Prometheus header component', () => { - it('should show a title', () => { - const title = prometheusHeader.find({ ref: 'title' }).text(); - - expect(title).toBe('graph header'); - }); - }); -}); diff --git a/spec/lib/gitlab/serverless/domain_spec.rb b/spec/lib/gitlab/serverless/domain_spec.rb deleted file mode 100644 index ae5551977d4..00000000000 --- a/spec/lib/gitlab/serverless/domain_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::Serverless::Domain do - describe '.generate_uuid' do - it 'has 14 characters' do - expect(described_class.generate_uuid.length).to eq(described_class::UUID_LENGTH) - end - - it 'consists of only hexadecimal characters' do - expect(described_class.generate_uuid).to match(/\A\h+\z/) - end - - it 'uses random characters' do - uuid = 'abcd1234567890' - - expect(SecureRandom).to receive(:hex).with(described_class::UUID_LENGTH / 2).and_return(uuid) - expect(described_class.generate_uuid).to eq(uuid) - end - end -end diff --git a/spec/lib/gitlab/serverless/function_uri_spec.rb b/spec/lib/gitlab/serverless/function_uri_spec.rb deleted file mode 100644 index cd4abeb89f5..00000000000 --- a/spec/lib/gitlab/serverless/function_uri_spec.rb +++ /dev/null @@ -1,81 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::Serverless::FunctionURI do - let(:function) { 'test-function' } - let(:domain) { 'serverless.gitlab.io' } - let(:pages_domain) { create(:pages_domain, :instance_serverless, domain: domain) } - let!(:cluster) { create(:serverless_domain_cluster, uuid: 'abcdef12345678', pages_domain: pages_domain) } - let(:valid_cluster) { 'aba1cdef123456f278' } - let(:invalid_cluster) { 'aba1cdef123456f178' } - let!(:environment) { create(:environment, name: 'test') } - - let(:valid_uri) { "https://#{function}-#{valid_cluster}#{"%x" % environment.id}-#{environment.slug}.#{domain}" } - let(:valid_fqdn) { "#{function}-#{valid_cluster}#{"%x" % environment.id}-#{environment.slug}.#{domain}" } - let(:invalid_uri) { "https://#{function}-#{invalid_cluster}#{"%x" % environment.id}-#{environment.slug}.#{domain}" } - - shared_examples 'a valid FunctionURI class' do - describe '#to_s' do - it 'matches valid URI' do - expect(subject.to_s).to eq valid_uri - end - end - - describe '#function' do - it 'returns function' do - expect(subject.function).to eq function - end - end - - describe '#cluster' do - it 'returns cluster' do - expect(subject.cluster).to eq cluster - end - end - - describe '#environment' do - it 'returns environment' do - expect(subject.environment).to eq environment - end - end - end - - describe '.new' do - context 'with valid arguments' do - subject { described_class.new(function: function, cluster: cluster, environment: environment) } - - it_behaves_like 'a valid FunctionURI class' - end - - context 'with invalid arguments' do - subject { described_class.new(function: function, environment: environment) } - - it 'raises an exception' do - expect { subject }.to raise_error(ArgumentError) - end - end - end - - describe '.parse' do - context 'with valid URI' do - subject { described_class.parse(valid_uri) } - - it_behaves_like 'a valid FunctionURI class' - end - - context 'with valid FQDN' do - subject { described_class.parse(valid_fqdn) } - - it_behaves_like 'a valid FunctionURI class' - end - - context 'with invalid URI' do - subject { described_class.parse(invalid_uri) } - - it 'returns nil' do - expect(subject).to be_nil - end - end - end -end diff --git a/spec/lib/gitlab/serverless/service_spec.rb b/spec/lib/gitlab/serverless/service_spec.rb index f618dd02cdb..6db8b9cd0ba 100644 --- a/spec/lib/gitlab/serverless/service_spec.rb +++ b/spec/lib/gitlab/serverless/service_spec.rb @@ -94,17 +94,19 @@ describe Gitlab::Serverless::Service do end describe '#url' do + let(:serverless_domain) { instance_double(::Serverless::Domain, uri: URI('https://proxy.example.com')) } + it 'returns proxy URL if cluster has serverless domain' do # cluster = create(:cluster) knative = create(:clusters_applications_knative, :installed, cluster: cluster) create(:serverless_domain_cluster, clusters_applications_knative_id: knative.id) service = Gitlab::Serverless::Service.new(attributes.merge('cluster' => cluster)) - expect(Gitlab::Serverless::FunctionURI).to receive(:new).with( - function: service.name, - cluster: service.cluster.serverless_domain, + expect(::Serverless::Domain).to receive(:new).with( + function_name: service.name, + serverless_domain_cluster: service.cluster.serverless_domain, environment: service.environment - ).and_return('https://proxy.example.com') + ).and_return(serverless_domain) expect(service.url).to eq('https://proxy.example.com') end diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index ba344a234b8..04e4d261b1c 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -274,7 +274,8 @@ describe Clusters::Applications::Prometheus do subject { application.files_with_replaced_values({ hello: :world }) } it 'does not modify #files' do - expect(subject[:'values.yaml']).not_to eq(files) + expect(subject[:'values.yaml']).not_to eq(files[:'values.yaml']) + expect(files[:'values.yaml']).to eq(application.values) end @@ -282,27 +283,17 @@ describe Clusters::Applications::Prometheus do expect(subject[:'values.yaml']).to eq({ hello: :world }) end - it 'includes cert files' do - expect(subject[:'ca.pem']).to be_present - expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert) - - expect(subject[:'cert.pem']).to be_present - expect(subject[:'key.pem']).to be_present - - cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem']) - expect(cert.not_after).to be < 60.minutes.from_now - end - - context 'when the helm application does not have a ca_cert' do - before do - application.cluster.application_helm.ca_cert = nil - end - - it 'does not include cert files' do - expect(subject[:'ca.pem']).not_to be_present - expect(subject[:'cert.pem']).not_to be_present - expect(subject[:'key.pem']).not_to be_present - end + it 'uses values from #files, except for values.yaml' do + allow(application).to receive(:files).and_return({ + 'values.yaml': 'some value specific to files', + 'file_a.txt': 'file_a', + 'file_b.txt': 'file_b' + }) + + expect(subject.except(:'values.yaml')).to eq({ + 'file_a.txt': 'file_a', + 'file_b.txt': 'file_b' + }) end end diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 72143d69fc8..48cabd4301c 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -1264,6 +1264,14 @@ describe Environment, :use_clean_rails_memory_store_caching do end end + describe '.for_id_and_slug' do + subject { described_class.for_id_and_slug(environment.id, environment.slug) } + + let(:environment) { create(:environment) } + + it { is_expected.not_to be_nil } + end + describe '.find_or_create_by_name' do it 'finds an existing environment if it exists' do env = create(:environment) diff --git a/spec/models/serverless/domain_cluster_spec.rb b/spec/models/serverless/domain_cluster_spec.rb index bd645b7d0aa..f5e1eb304a1 100644 --- a/spec/models/serverless/domain_cluster_spec.rb +++ b/spec/models/serverless/domain_cluster_spec.rb @@ -10,7 +10,7 @@ describe ::Serverless::DomainCluster do it { is_expected.to validate_presence_of(:knative) } it { is_expected.to validate_presence_of(:uuid) } - it { is_expected.to validate_length_of(:uuid).is_equal_to(Gitlab::Serverless::Domain::UUID_LENGTH) } + it { is_expected.to validate_length_of(:uuid).is_equal_to(::Serverless::Domain::UUID_LENGTH) } it { is_expected.to validate_uniqueness_of(:uuid) } it 'validates that uuid has only hex characters' do @@ -31,7 +31,7 @@ describe ::Serverless::DomainCluster do context 'when nil' do it 'generates a value by default' do attributes = build(:serverless_domain_cluster).attributes.merge(uuid: nil) - expect(Gitlab::Serverless::Domain).to receive(:generate_uuid).and_call_original + expect(::Serverless::Domain).to receive(:generate_uuid).and_call_original subject = Serverless::DomainCluster.new(attributes) @@ -47,6 +47,10 @@ describe ::Serverless::DomainCluster do end end + describe 'cluster' do + it { is_expected.to respond_to(:cluster) } + end + describe 'domain' do it { is_expected.to respond_to(:domain) } end diff --git a/spec/models/serverless/domain_spec.rb b/spec/models/serverless/domain_spec.rb new file mode 100644 index 00000000000..ba54e05b4e3 --- /dev/null +++ b/spec/models/serverless/domain_spec.rb @@ -0,0 +1,97 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Serverless::Domain do + let(:function_name) { 'test-function' } + let(:pages_domain_name) { 'serverless.gitlab.io' } + let(:pages_domain) { create(:pages_domain, :instance_serverless, domain: pages_domain_name) } + let!(:serverless_domain_cluster) { create(:serverless_domain_cluster, uuid: 'abcdef12345678', pages_domain: pages_domain) } + let(:valid_cluster_uuid) { 'aba1cdef123456f278' } + let(:invalid_cluster_uuid) { 'aba1cdef123456f178' } + let!(:environment) { create(:environment, name: 'test') } + + let(:valid_uri) { "https://#{function_name}-#{valid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" } + let(:valid_fqdn) { "#{function_name}-#{valid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" } + let(:invalid_uri) { "https://#{function_name}-#{invalid_cluster_uuid}#{"%x" % environment.id}-#{environment.slug}.#{pages_domain_name}" } + + shared_examples 'a valid Domain' do + describe '#uri' do + it 'matches valid URI' do + expect(subject.uri.to_s).to eq valid_uri + end + end + + describe '#function_name' do + it 'returns function_name' do + expect(subject.function_name).to eq function_name + end + end + + describe '#serverless_domain_cluster' do + it 'returns serverless_domain_cluster' do + expect(subject.serverless_domain_cluster).to eq serverless_domain_cluster + end + end + + describe '#environment' do + it 'returns environment' do + expect(subject.environment).to eq environment + end + end + end + + describe '.new' do + context 'with valid arguments' do + subject do + described_class.new( + function_name: function_name, + serverless_domain_cluster: serverless_domain_cluster, + environment: environment + ) + end + + it_behaves_like 'a valid Domain' + end + + context 'with invalid arguments' do + subject do + described_class.new( + function_name: function_name, + environment: environment + ) + end + + it { is_expected.not_to be_valid } + end + + context 'with nil cluster argument' do + subject do + described_class.new( + function_name: function_name, + serverless_domain_cluster: nil, + environment: environment + ) + end + + it { is_expected.not_to be_valid } + end + end + + describe '.generate_uuid' do + it 'has 14 characters' do + expect(described_class.generate_uuid.length).to eq(described_class::UUID_LENGTH) + end + + it 'consists of only hexadecimal characters' do + expect(described_class.generate_uuid).to match(/\A\h+\z/) + end + + it 'uses random characters' do + uuid = 'abcd1234567890' + + expect(SecureRandom).to receive(:hex).with(described_class::UUID_LENGTH / 2).and_return(uuid) + expect(described_class.generate_uuid).to eq(uuid) + end + end +end diff --git a/spec/support/shared_examples/models/cluster_application_helm_cert_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_helm_cert_shared_examples.rb index d5c425dea51..fa6b0c3afdd 100644 --- a/spec/support/shared_examples/models/cluster_application_helm_cert_shared_examples.rb +++ b/spec/support/shared_examples/models/cluster_application_helm_cert_shared_examples.rb @@ -28,22 +28,46 @@ RSpec.shared_examples 'cluster application helm specs' do |application_name| describe '#files' do subject { application.files } - context 'when the helm application does not have a ca_cert' do + context 'managed_apps_local_tiller feature flag is disabled' do before do - application.cluster.application_helm.ca_cert = nil + stub_feature_flags(managed_apps_local_tiller: false) end - it 'does not include cert files when there is no ca_cert entry' do - expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem') + context 'when the helm application does not have a ca_cert' do + before do + application.cluster.application_helm.ca_cert = nil + end + + it 'does not include cert files when there is no ca_cert entry' do + expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem') + end + end + + it 'includes cert files when there is a ca_cert entry' do + expect(subject).to include(:'ca.pem', :'cert.pem', :'key.pem') + expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert) + + cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem']) + expect(cert.not_after).to be < 60.minutes.from_now end end - it 'includes cert files when there is a ca_cert entry' do - expect(subject).to include(:'ca.pem', :'cert.pem', :'key.pem') - expect(subject[:'ca.pem']).to eq(application.cluster.application_helm.ca_cert) + context 'managed_apps_local_tiller feature flag is enabled' do + before do + stub_feature_flags(managed_apps_local_tiller: true) + end + + it 'does not include cert files' do + expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem') + end + + context 'when cluster does not have helm installed' do + let(:application) { create(application_name, :no_helm_installed) } - cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem']) - expect(cert.not_after).to be < 60.minutes.from_now + it 'does not include cert files' do + expect(subject).not_to include(:'ca.pem', :'cert.pem', :'key.pem') + end + end end end end diff --git a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb index e4e49b94e42..6c772ddf897 100644 --- a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb +++ b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb @@ -48,14 +48,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name| expect(subject).to be_installed end - it 'updates helm version' do - subject.cluster.application_helm.update!(version: '1.2.3') + context 'managed_apps_local_tiller feature flag disabled' do + before do + stub_feature_flags(managed_apps_local_tiller: false) + end - subject.make_installed! + it 'updates helm version' do + subject.cluster.application_helm.update!(version: '1.2.3') - subject.cluster.application_helm.reload + subject.make_installed! - expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION) + subject.cluster.application_helm.reload + + expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION) + end + end + + context 'managed_apps_local_tiller feature flag enabled' do + before do + stub_feature_flags(managed_apps_local_tiller: true) + end + + it 'does not update the helm version' do + subject.cluster.application_helm.update!(version: '1.2.3') + + expect do + subject.make_installed! + + subject.cluster.application_helm.reload + end.not_to change { subject.cluster.application_helm.version } + end + + context 'the cluster has no helm installed' do + subject { create(application_name, :installing, :no_helm_installed) } + + it 'runs without errors' do + expect { subject.make_installed! }.not_to raise_error + end + end end it 'sets the correct version of the application' do @@ -77,14 +107,44 @@ RSpec.shared_examples 'cluster application status specs' do |application_name| expect(subject).to be_updated end - it 'updates helm version' do - subject.cluster.application_helm.update!(version: '1.2.3') + context 'managed_apps_local_tiller feature flag disabled' do + before do + stub_feature_flags(managed_apps_local_tiller: false) + end - subject.make_installed! + it 'updates helm version' do + subject.cluster.application_helm.update!(version: '1.2.3') - subject.cluster.application_helm.reload + subject.make_installed! - expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION) + subject.cluster.application_helm.reload + + expect(subject.cluster.application_helm.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION) + end + end + + context 'managed_apps_local_tiller feature flag enabled' do + before do + stub_feature_flags(managed_apps_local_tiller: true) + end + + it 'does not update the helm version' do + subject.cluster.application_helm.update!(version: '1.2.3') + + expect do + subject.make_installed! + + subject.cluster.application_helm.reload + end.not_to change { subject.cluster.application_helm.version } + end + + context 'the cluster has no helm installed' do + subject { create(application_name, :updating, :no_helm_installed) } + + it 'runs without errors' do + expect { subject.make_installed! }.not_to raise_error + end + end end it 'updates the version of the application' do |