Refactor specs to run shared parts only when used

All applications except for Jupyter have the same #set_initial_status,
so create a new shared example which we include in all application specs
except for juptyer_spec. Juptyer specs already have specs for it's
version of #set_initial_status
This commit is contained in:
Thong Kuah 2019-02-07 00:05:21 +13:00
parent e72f24d27b
commit d204ec3d37
7 changed files with 34 additions and 24 deletions

View File

@ -5,6 +5,7 @@ describe Clusters::Applications::CertManager do
include_examples 'cluster application core specs', :clusters_applications_cert_managers
include_examples 'cluster application status specs', :clusters_applications_cert_managers
include_examples 'cluster application initial status specs'
describe '#install_command' do
let(:cluster_issuer_file) { { "cluster_issuer.yaml": "---\napiVersion: certmanager.k8s.io/v1alpha1\nkind: ClusterIssuer\nmetadata:\n name: letsencrypt-prod\nspec:\n acme:\n server: https://acme-v02.api.letsencrypt.org/directory\n email: admin@example.com\n privateKeySecretRef:\n name: letsencrypt-prod\n http01: {}\n" } }

View File

@ -8,6 +8,7 @@ describe Clusters::Applications::Ingress do
include_examples 'cluster application core specs', :clusters_applications_ingress
include_examples 'cluster application status specs', :clusters_applications_ingress
include_examples 'cluster application helm specs', :clusters_applications_ingress
include_examples 'cluster application initial status specs'
before do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)

View File

@ -9,6 +9,7 @@ describe Clusters::Applications::Knative do
include_examples 'cluster application core specs', :clusters_applications_knative
include_examples 'cluster application status specs', :clusters_applications_knative
include_examples 'cluster application helm specs', :clusters_applications_knative
include_examples 'cluster application initial status specs'
before do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)

View File

@ -6,6 +6,7 @@ describe Clusters::Applications::Prometheus do
include_examples 'cluster application core specs', :clusters_applications_prometheus
include_examples 'cluster application status specs', :clusters_applications_prometheus
include_examples 'cluster application helm specs', :clusters_applications_prometheus
include_examples 'cluster application initial status specs'
describe '.installed' do
subject { described_class.installed }

View File

@ -6,6 +6,7 @@ describe Clusters::Applications::Runner do
include_examples 'cluster application core specs', :clusters_applications_runner
include_examples 'cluster application status specs', :clusters_applications_runner
include_examples 'cluster application helm specs', :clusters_applications_runner
include_examples 'cluster application initial status specs'
it { is_expected.to belong_to(:runner) }

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
shared_examples 'cluster application initial status specs' do
describe '#status' do
let(:cluster) { create(:cluster, :provided_by_gcp) }
subject { described_class.new(cluster: cluster) }
context 'when application helm is scheduled' do
before do
create(:clusters_applications_helm, :scheduled, cluster: cluster)
end
it 'defaults to :not_installable' do
expect(subject.status_name).to be(:not_installable)
end
end
context 'when application is scheduled' do
before do
create(:clusters_applications_helm, :installed, cluster: cluster)
end
it 'sets a default status' do
expect(subject.status_name).to be(:installable)
end
end
end
end

View File

@ -7,30 +7,6 @@ shared_examples 'cluster application status specs' do |application_name|
it 'sets a default status' do
expect(subject.status_name).to be(:not_installable)
end
context 'when application helm is scheduled' do
before do
create(:clusters_applications_helm, :scheduled, cluster: cluster)
end
it 'defaults to :not_installable' do
expect(subject.status_name).to be(:not_installable)
end
end
context 'when application is scheduled' do
before do
create(:clusters_applications_helm, :installed, cluster: cluster)
if described_class == Clusters::Applications::Jupyter
create(:clusters_applications_ingress, :installed, external_ip: '127.0.0.1', cluster: cluster)
end
end
it 'sets a default status' do
expect(subject.status_name).to be(:installable)
end
end
end
describe 'status state machine' do