Commit 389c9bfc authored by Kamil Trzcinski's avatar Kamil Trzcinski

Add specs for ingress

parent e40021cd
FactoryGirl.define do
factory :cluster_applications_ingress, class: Clusters::Applications::Ingress do
cluster factory: %i(cluster provided_by_gcp)
trait :not_installable do
status -2
end
trait :installable do
status 0
end
trait :scheduled do
status 1
end
trait :installing do
status 2
end
trait :installed do
status 3
end
trait :errored do
status(-1)
status_reason 'something went wrong'
end
trait :timeouted do
installing
updated_at ClusterWaitForAppInstallationWorker::TIMEOUT.ago
end
end
end
require 'rails_helper'
describe Clusters::Applications::Ingress do
it { is_expected.to belong_to(:cluster) }
it { is_expected.to validate_presence_of(:cluster) }
describe '#name' do
it 'is .application_name' do
expect(subject.name).to eq(described_class.application_name)
end
it 'is recorded in Clusters::Cluster::APPLICATIONS' do
expect(Clusters::Cluster::APPLICATIONS[subject.name]).to eq(described_class)
end
end
describe '#status' do
let(:cluster) { create(:cluster, :provided_by_gcp) }
subject { described_class.new(cluster: cluster) }
it 'defaults to :not_installable' do
expect(subject.status_name).to be(:not_installable)
end
context 'when application helm is defined' do
before do
create(:cluster_applications_ingress, cluster: cluster)
end
it 'defaults to :installable' do
expect(subject.status_name).to be(:installable)
end
end
end
describe 'status state machine' do
describe '#make_installing' do
subject { create(:cluster_applications_ingress, :scheduled) }
it 'is installing' do
subject.make_installing!
expect(subject).to be_installing
end
end
describe '#make_installed' do
subject { create(:cluster_applications_ingress, :installing) }
it 'is installed' do
subject.make_installed
expect(subject).to be_installed
end
end
describe '#make_errored' do
subject { create(:cluster_applications_ingress, :installing) }
let(:reason) { 'some errors' }
it 'is errored' do
subject.make_errored(reason)
expect(subject).to be_errored
expect(subject.status_reason).to eq(reason)
end
end
describe '#make_scheduled' do
subject { create(:cluster_applications_ingress, :installable) }
it 'is scheduled' do
subject.make_scheduled
expect(subject).to be_scheduled
end
describe 'when was errored' do
subject { create(:cluster_applications_ingress, :errored) }
it 'clears #status_reason' do
expect(subject.status_reason).not_to be_nil
subject.make_scheduled!
expect(subject.status_reason).to be_nil
end
end
end
end
end
...@@ -178,4 +178,25 @@ describe Clusters::Cluster do ...@@ -178,4 +178,25 @@ describe Clusters::Cluster do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
end end
describe '#applications' do
set(:cluster) { create(:cluster) }
subject { cluster.applications }
context 'when none of applications are created' do
it 'returns a list of a new objects' do
is_expected.not_to be_empty
end
end
context 'when applications are created' do
let!(:helm) { create(:cluster_applications_helm, cluster: cluster) }
let!(:ingress) { create(:cluster_applications_ingress, cluster: cluster) }
it 'returns a list of created applications' do
is_expected.to contain_exactly(helm, ingress)
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment