diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2017-11-03 19:20:29 +0100 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2017-11-03 19:20:29 +0100 |
commit | c6c9b37b1d1c9304b0eef530adb4d32178adae16 (patch) | |
tree | 5daf2d4220c36401c471550d18b0e397e602bcdb /spec | |
parent | c0299ce49406302a26e7fd16ec272bca19715afb (diff) | |
download | gitlab-ce-c6c9b37b1d1c9304b0eef530adb4d32178adae16.tar.gz |
Add Clusters::Applications::Helm tests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/clusters/applications/helm.rb | 35 | ||||
-rw-r--r-- | spec/models/clusters/applications/helm_spec.rb | 82 |
2 files changed, 111 insertions, 6 deletions
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb new file mode 100644 index 00000000000..968a6a1a007 --- /dev/null +++ b/spec/factories/clusters/applications/helm.rb @@ -0,0 +1,35 @@ +FactoryGirl.define do + factory :applications_helm, class: Clusters::Applications::Helm do + trait :cluster do + before(:create) do |app, _| + app.cluster = create(:cluster) + end + end + + trait :installable do + cluster + status 0 + end + + trait :scheduled do + cluster + status 1 + end + + trait :installing do + cluster + status 2 + end + + trait :installed do + cluster + status 3 + end + + trait :errored do + cluster + status(-1) + status_reason 'something went wrong' + end + end +end diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb index 6e32e2e7037..54fce7d886a 100644 --- a/spec/models/clusters/applications/helm_spec.rb +++ b/spec/models/clusters/applications/helm_spec.rb @@ -1,14 +1,84 @@ require 'rails_helper' -require_relative '../kubernetes_spec' RSpec.describe Clusters::Applications::Helm, type: :model do - it_behaves_like 'a registered kubernetes app' + it { is_expected.to belong_to(:cluster) } + it { is_expected.to validate_presence_of(:cluster) } - it { is_expected.to belong_to(:kubernetes_service) } + 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 '#version' do + it 'defaults to Gitlab::Kubernetes::Helm::HELM_VERSION' do + expect(subject.version).to eq(Gitlab::Kubernetes::Helm::HELM_VERSION) + end + end + + describe '#status' do + it 'defaults to :installable' do + expect(subject.status_name).to be(:installable) + end + end + + describe 'status state machine' do + describe '#make_installing' do + subject { create(:applications_helm, :scheduled) } + + it 'is installing' do + subject.make_installing! + + expect(subject).to be_installing + end + end + + describe '#make_installed' do + subject { create(:applications_helm, :installing) } + + it 'is installed' do + subject.make_installed + + expect(subject).to be_installed + end + end + + describe '#make_errored' do + subject { create(:applications_helm, :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(:applications_helm, :installable) } + + it 'is scheduled' do + subject.make_scheduled + + expect(subject).to be_scheduled + end + + describe 'when was errored' do + subject { create(:applications_helm, :errored) } + + it 'clears #status_reason' do + expect(subject.status_reason).not_to be_nil + + subject.make_scheduled! - describe '#cluster' do - it 'is an alias to #kubernetes_service' do - expect(subject.method(:cluster).original_name).to eq(:kubernetes_service) + expect(subject.status_reason).to be_nil + end + end end end end |