Commit 67558190 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '217562-follow-up-from-add-endpoint-for-serialized-dag-pipeline' into 'master'

Test DAG pipeline serializers with schema matchers

See merge request gitlab-org/gitlab!36242
parents 1834d622 476a3da1
{
"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 ...@@ -11,10 +11,18 @@ RSpec.describe Ci::DagJobEntity do
describe '#as_json' do describe '#as_json' do
subject { entity.as_json } 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 it 'contains the name' do
expect(subject[:name]).to eq 'dag_job' expect(subject[:name]).to eq 'dag_job'
end end
it_behaves_like "matches schema"
context 'when job is stage scheduled' do context 'when job is stage scheduled' do
it 'contains the name scheduling_type' do it 'contains the name scheduling_type' do
expect(subject[:scheduling_type]).to eq 'stage' expect(subject[:scheduling_type]).to eq 'stage'
...@@ -23,6 +31,8 @@ RSpec.describe Ci::DagJobEntity do ...@@ -23,6 +31,8 @@ RSpec.describe Ci::DagJobEntity do
it 'does not expose needs' do it 'does not expose needs' do
expect(subject).not_to include(:needs) expect(subject).not_to include(:needs)
end end
it_behaves_like "matches schema"
end end
context 'when job is dag scheduled' do context 'when job is dag scheduled' do
...@@ -32,18 +42,24 @@ RSpec.describe Ci::DagJobEntity do ...@@ -32,18 +42,24 @@ RSpec.describe Ci::DagJobEntity do
expect(subject[:scheduling_type]).to eq 'dag' expect(subject[:scheduling_type]).to eq 'dag'
end end
it_behaves_like "matches schema"
context 'when job has needs' do context 'when job has needs' do
let!(:need) { create(:ci_build_need, build: job, name: 'compile') } let!(:need) { create(:ci_build_need, build: job, name: 'compile') }
it 'exposes the array of needs' do it 'exposes the array of needs' do
expect(subject[:needs]).to eq ['compile'] expect(subject[:needs]).to eq ['compile']
end end
it_behaves_like "matches schema"
end end
context 'when job has empty needs' do context 'when job has empty needs' do
it 'exposes an empty array of needs' do it 'exposes an empty array of needs' do
expect(subject[:needs]).to eq [] expect(subject[:needs]).to eq []
end end
it_behaves_like "matches schema"
end end
end end
end end
......
...@@ -31,6 +31,10 @@ RSpec.describe Ci::DagJobGroupEntity do ...@@ -31,6 +31,10 @@ RSpec.describe Ci::DagJobGroupEntity do
expect(exposed_jobs.size).to eq 1 expect(exposed_jobs.size).to eq 1
expect(exposed_jobs.first.fetch(:name)).to eq 'test' expect(exposed_jobs.first.fetch(:name)).to eq 'test'
end end
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_job_group')
end
end end
context 'when group contains multiple parallel jobs' do context 'when group contains multiple parallel jobs' do
...@@ -53,6 +57,10 @@ RSpec.describe Ci::DagJobGroupEntity do ...@@ -53,6 +57,10 @@ RSpec.describe Ci::DagJobGroupEntity do
expect(exposed_jobs.first.fetch(:name)).to eq 'test 1/2' expect(exposed_jobs.first.fetch(:name)).to eq 'test 1/2'
expect(exposed_jobs.last.fetch(:name)).to eq 'test 2/2' expect(exposed_jobs.last.fetch(:name)).to eq 'test 2/2'
end end
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_job_group')
end
end end
end end
end end
...@@ -11,12 +11,20 @@ RSpec.describe Ci::DagPipelineEntity do ...@@ -11,12 +11,20 @@ RSpec.describe Ci::DagPipelineEntity do
describe '#as_json' do describe '#as_json' do
subject { entity.as_json } 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 context 'when pipeline is empty' do
it 'contains stages' do it 'contains stages' do
expect(subject).to include(:stages) expect(subject).to include(:stages)
expect(subject[:stages]).to be_empty expect(subject[:stages]).to be_empty
end end
it_behaves_like "matches schema"
end end
context 'when pipeline has jobs' do context 'when pipeline has jobs' do
...@@ -30,6 +38,8 @@ RSpec.describe Ci::DagPipelineEntity do ...@@ -30,6 +38,8 @@ RSpec.describe Ci::DagPipelineEntity do
expect(stages.size).to eq 3 expect(stages.size).to eq 3
expect(stages.map { |s| s[:name] }).to contain_exactly('build', 'test', 'deploy') expect(stages.map { |s| s[:name] }).to contain_exactly('build', 'test', 'deploy')
end end
it_behaves_like "matches schema"
end end
context 'when pipeline has parallel jobs, DAG needs and GenericCommitStatus' do context 'when pipeline has parallel jobs, DAG needs and GenericCommitStatus' do
...@@ -138,6 +148,8 @@ RSpec.describe Ci::DagPipelineEntity 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].fetch(:name)).to eq 'deploy'
expect(subject.fetch(:stages)[2]).to eq expected_result.fetch(:stages)[2] expect(subject.fetch(:stages)[2]).to eq expected_result.fetch(:stages)[2]
end end
it_behaves_like "matches schema"
end end
end end
end end
...@@ -13,5 +13,9 @@ RSpec.describe Ci::DagPipelineSerializer do ...@@ -13,5 +13,9 @@ RSpec.describe Ci::DagPipelineSerializer do
expect(subject[:stages]).to be_present expect(subject[:stages]).to be_present
expect(subject[:stages].size).to eq 1 expect(subject[:stages].size).to eq 1
end end
it 'matches schema' do
expect(subject.to_json).to match_schema('entities/dag_pipeline')
end
end end
end end
...@@ -27,5 +27,9 @@ RSpec.describe Ci::DagStageEntity do ...@@ -27,5 +27,9 @@ RSpec.describe Ci::DagStageEntity do
expect(job_group[:size]).to eq 1 expect(job_group[:size]).to eq 1
expect(job_group[:jobs]).not_to be_empty expect(job_group[:jobs]).not_to be_empty
end end
it "matches schema" do
expect(subject.to_json).to match_schema('entities/dag_stage')
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