Add ClusterApplicationEntity tests

This commit is contained in:
Alessio Caiazza 2017-11-06 17:02:28 +01:00
parent b893a85880
commit 2802b5bb52
No known key found for this signature in database
GPG Key ID: 8655B9CB5B8B512E
6 changed files with 55 additions and 20 deletions

View File

@ -1,4 +1,4 @@
class ClusterAppEntity < Grape::Entity
class ClusterApplicationEntity < Grape::Entity
expose :name
expose :status_name, as: :status
expose :status_reason

View File

@ -3,5 +3,5 @@ class ClusterEntity < Grape::Entity
expose :status_name, as: :status
expose :status_reason
expose :applications, using: ClusterAppEntity
expose :applications, using: ClusterApplicationEntity
end

View File

@ -1,42 +1,38 @@
{
"type": "object",
"required" : [
"status"
"status",
"applications"
],
"properties" : {
"status": { "type": "string" },
"status_reason": { "type": ["string", "null"] },
"applications": { "$ref": "#/definitions/applications" }
"applications": {
"type": "array",
"items": { "$ref": "#/definitions/application_status" }
}
},
"additionalProperties": false,
"definitions": {
"applications": {
"type": "object",
"additionalProperties": false,
"properties" : {
"helm": { "$ref": "#/definitions/app_status" },
"runner": { "$ref": "#/definitions/app_status" },
"ingress": { "$ref": "#/definitions/app_status" },
"prometheus": { "$ref": "#/definitions/app_status" }
}
},
"app_status": {
"application_status": {
"type": "object",
"additionalProperties": false,
"properties" : {
"name": { "type": "string" },
"status": {
"type": {
"enum": [
"installable",
"scheduled",
"installing",
"installed",
"error"
"errored"
]
}
},
"status_reason": { "type": ["string", "null"] }
},
"required" : [ "status" ]
"required" : [ "name", "status" ]
}
}
}

View File

@ -0,0 +1,30 @@
require 'spec_helper'
describe ClusterApplicationEntity do
describe '#as_json' do
let(:application) { build(:applications_helm) }
subject { described_class.new(application).as_json }
it 'has name' do
expect(subject[:name]).to eq(application.name)
end
it 'has status' do
expect(subject[:status]).to eq(:installable)
end
it 'has no status_reason' do
expect(subject[:status_reason]).to be_nil
end
context 'when application is errored' do
let(:application) { build(:applications_helm, :errored) }
it 'has corresponded data' do
expect(subject[:status]).to eq(:errored)
expect(subject[:status_reason]).not_to be_nil
expect(subject[:status_reason]).to eq(application.status_reason)
end
end
end
end

View File

@ -35,8 +35,17 @@ describe ClusterEntity do
end
end
it 'contains applications' do
expect(subject[:applications]).to eq({})
context 'when no application has been installed' do
let(:cluster) { create(:cluster) }
subject { described_class.new(cluster).as_json[:applications]}
it 'contains helm as installable' do
expect(subject).not_to be_empty
helm = subject[0]
expect(helm[:name]).to eq('helm')
expect(helm[:status]).to eq(:installable)
end
end
end
end

View File

@ -9,7 +9,7 @@ describe ClusterSerializer do
let(:provider) { create(:provider_gcp, :errored) }
it 'serializes only status' do
expect(subject.keys).to contain_exactly(:status, :status_reason)
expect(subject.keys).to contain_exactly(:status, :status_reason, :applications)
end
end