summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2017-11-06 17:02:28 +0100
committerAlessio Caiazza <acaiazza@gitlab.com>2017-11-06 17:02:28 +0100
commit2802b5bb52b6ba28e6eeb1813f3fd3a79d2c03c4 (patch)
tree57bb23f3ec8f808209059cf1b4791b5cefeb20f9
parentb893a858808f1e2aefca4e3f665d633d31fa5937 (diff)
downloadgitlab-ce-2802b5bb52b6ba28e6eeb1813f3fd3a79d2c03c4.tar.gz
Add ClusterApplicationEntity tests
-rw-r--r--app/serializers/cluster_application_entity.rb (renamed from app/serializers/cluster_app_entity.rb)2
-rw-r--r--app/serializers/cluster_entity.rb2
-rw-r--r--spec/fixtures/api/schemas/cluster_status.json26
-rw-r--r--spec/serializers/cluster_application_entity_spec.rb30
-rw-r--r--spec/serializers/cluster_entity_spec.rb13
-rw-r--r--spec/serializers/cluster_serializer_spec.rb2
6 files changed, 55 insertions, 20 deletions
diff --git a/app/serializers/cluster_app_entity.rb b/app/serializers/cluster_application_entity.rb
index 7da2d4921a2..3f9a275ad08 100644
--- a/app/serializers/cluster_app_entity.rb
+++ b/app/serializers/cluster_application_entity.rb
@@ -1,4 +1,4 @@
-class ClusterAppEntity < Grape::Entity
+class ClusterApplicationEntity < Grape::Entity
expose :name
expose :status_name, as: :status
expose :status_reason
diff --git a/app/serializers/cluster_entity.rb b/app/serializers/cluster_entity.rb
index e775c68eb6b..7e5b0997878 100644
--- a/app/serializers/cluster_entity.rb
+++ b/app/serializers/cluster_entity.rb
@@ -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
diff --git a/spec/fixtures/api/schemas/cluster_status.json b/spec/fixtures/api/schemas/cluster_status.json
index 451ea50f0f9..489d563be2b 100644
--- a/spec/fixtures/api/schemas/cluster_status.json
+++ b/spec/fixtures/api/schemas/cluster_status.json
@@ -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" ]
}
}
}
diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb
new file mode 100644
index 00000000000..61cebcefa28
--- /dev/null
+++ b/spec/serializers/cluster_application_entity_spec.rb
@@ -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
diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb
index abfc3731fb2..c58ee1a1ea6 100644
--- a/spec/serializers/cluster_entity_spec.rb
+++ b/spec/serializers/cluster_entity_spec.rb
@@ -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
diff --git a/spec/serializers/cluster_serializer_spec.rb b/spec/serializers/cluster_serializer_spec.rb
index 04d8728303c..a6dd2309663 100644
--- a/spec/serializers/cluster_serializer_spec.rb
+++ b/spec/serializers/cluster_serializer_spec.rb
@@ -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