Commit 476a3da1 authored by Allison Browne's avatar Allison Browne Committed by Douglas Barbosa Alexandre

Add schemas for matching to dag pipelines

Test dag pipeline schemas via a serializer
parent 2c966430
{
"type": "object",
"required": ["name", "scheduling_type"],
"properties": {
"name": { "type": "string" },
"scheduling_type": { "type": ["string", null] },
"needs": { "type": "array" }
},
"additionalProperties": false
}
{
"type": "object",
"required": ["name", "size", "jobs"],
"properties": {
"name": { "type": "string" },
"size": { "type": "integer" },
"jobs": {
"type": "array",
"items": { "$ref": "dag_job.json" }
}
},
"additionalProperties": false
}
{
"type": "object",
"required": ["stages"],
"properties": {
"stages": {
"type": "array",
"items": { "$ref": "dag_stage.json" }
}
},
"additionalProperties": false
}
{
"type": "object",
"required": ["name", "groups"],
"properties": {
"name": { "type": "string" },
"groups": {
"type": "array",
"items": { "$ref": "dag_job_group.json" }
}
}
}
......@@ -11,10 +11,18 @@ RSpec.describe Ci::DagJobEntity do
describe '#as_json' do
subject { entity.as_json }
RSpec.shared_examples "matches schema" do
it "matches schema" do
expect(subject.to_json).to match_schema('entities/dag_job')
end
end
it 'contains the name' do
expect(subject[:name]).to eq 'dag_job'
end
it_behaves_like "matches schema"
context 'when job is stage scheduled' do
it 'contains the name scheduling_type' do
expect(subject[:scheduling_type]).to eq 'stage'
......@@ -23,6 +31,8 @@ RSpec.describe Ci::DagJobEntity do
it 'does not expose needs' do
expect(subject).not_to include(:needs)
end
it_behaves_like "matches schema"
end
context 'when job is dag scheduled' do
......@@ -32,18 +42,24 @@ RSpec.describe Ci::DagJobEntity do
expect(subject[:scheduling_type]).to eq 'dag'
end
it_behaves_like "matches schema"
context 'when job has needs' do
let!(:need) { create(:ci_build_need, build: job, name: 'compile') }
it 'exposes the array of needs' do
expect(subject[:needs]).to eq ['compile']
end
it_behaves_like "matches schema"
end
context 'when job has empty needs' do
it 'exposes an empty array of needs' do
expect(subject[:needs]).to eq []
end
it_behaves_like "matches schema"
end
end
end
......
......@@ -31,6 +31,10 @@ RSpec.describe Ci::DagJobGroupEntity do
expect(exposed_jobs.size).to eq 1
expect(exposed_jobs.first.fetch(:name)).to eq 'test'
end
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_job_group')
end
end
context 'when group contains multiple parallel jobs' do
......@@ -53,6 +57,10 @@ RSpec.describe Ci::DagJobGroupEntity do
expect(exposed_jobs.first.fetch(:name)).to eq 'test 1/2'
expect(exposed_jobs.last.fetch(:name)).to eq 'test 2/2'
end
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_job_group')
end
end
end
end
......@@ -11,12 +11,20 @@ RSpec.describe Ci::DagPipelineEntity do
describe '#as_json' do
subject { entity.as_json }
RSpec.shared_examples "matches schema" do
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_pipeline')
end
end
context 'when pipeline is empty' do
it 'contains stages' do
expect(subject).to include(:stages)
expect(subject[:stages]).to be_empty
end
it_behaves_like "matches schema"
end
context 'when pipeline has jobs' do
......@@ -30,6 +38,8 @@ RSpec.describe Ci::DagPipelineEntity do
expect(stages.size).to eq 3
expect(stages.map { |s| s[:name] }).to contain_exactly('build', 'test', 'deploy')
end
it_behaves_like "matches schema"
end
context 'when pipeline has parallel jobs, DAG needs and GenericCommitStatus' do
......@@ -138,6 +148,8 @@ RSpec.describe Ci::DagPipelineEntity do
expect(subject.fetch(:stages)[2].fetch(:name)).to eq 'deploy'
expect(subject.fetch(:stages)[2]).to eq expected_result.fetch(:stages)[2]
end
it_behaves_like "matches schema"
end
end
end
......@@ -13,5 +13,9 @@ RSpec.describe Ci::DagPipelineSerializer do
expect(subject[:stages]).to be_present
expect(subject[:stages].size).to eq 1
end
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_pipeline')
end
end
end
......@@ -27,5 +27,9 @@ RSpec.describe Ci::DagStageEntity do
expect(job_group[:size]).to eq 1
expect(job_group[:jobs]).not_to be_empty
end
it "matches schema" do
expect(subject.to_json).to match_schema('entities/dag_stage')
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