2020-12-04 13:09:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Query.ciConfig' do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
subject(:post_graphql_query) { post_graphql(query, current_user: user) }
|
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }
|
2020-12-04 13:09:55 -05:00
|
|
|
|
|
|
|
let_it_be(:content) do
|
|
|
|
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_includes.yml'))
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
query {
|
2021-01-13 07:10:27 -05:00
|
|
|
ciConfig(projectPath: "#{project.full_path}", content: "#{content}", dryRun: false) {
|
2020-12-04 13:09:55 -05:00
|
|
|
status
|
|
|
|
errors
|
2022-01-04 07:13:46 -05:00
|
|
|
warnings
|
2020-12-04 13:09:55 -05:00
|
|
|
stages {
|
2020-12-21 16:10:23 -05:00
|
|
|
nodes {
|
2020-12-04 13:09:55 -05:00
|
|
|
name
|
2020-12-21 16:10:23 -05:00
|
|
|
groups {
|
|
|
|
nodes {
|
2020-12-04 13:09:55 -05:00
|
|
|
name
|
2020-12-21 16:10:23 -05:00
|
|
|
size
|
|
|
|
jobs {
|
|
|
|
nodes {
|
|
|
|
name
|
|
|
|
groupName
|
|
|
|
stage
|
2021-01-13 07:10:27 -05:00
|
|
|
script
|
|
|
|
beforeScript
|
|
|
|
afterScript
|
|
|
|
allowFailure
|
|
|
|
only {
|
|
|
|
refs
|
|
|
|
}
|
|
|
|
when
|
|
|
|
except {
|
|
|
|
refs
|
|
|
|
}
|
|
|
|
environment
|
|
|
|
tags
|
2020-12-21 16:10:23 -05:00
|
|
|
needs {
|
|
|
|
nodes {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 13:09:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
it_behaves_like 'a working graphql query' do
|
|
|
|
before do
|
|
|
|
post_graphql_query
|
|
|
|
end
|
2020-12-04 13:09:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the correct structure' do
|
2020-12-25 04:10:31 -05:00
|
|
|
post_graphql_query
|
|
|
|
|
2020-12-04 13:09:55 -05:00
|
|
|
expect(graphql_data['ciConfig']).to eq(
|
|
|
|
"status" => "VALID",
|
|
|
|
"errors" => [],
|
2022-01-04 07:13:46 -05:00
|
|
|
"warnings" => [],
|
2020-12-04 13:09:55 -05:00
|
|
|
"stages" =>
|
2020-12-21 16:10:23 -05:00
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name" => "build",
|
|
|
|
"groups" =>
|
2020-12-04 13:09:55 -05:00
|
|
|
{
|
2020-12-21 16:10:23 -05:00
|
|
|
"nodes" =>
|
2020-12-04 13:09:55 -05:00
|
|
|
[
|
2020-12-21 16:10:23 -05:00
|
|
|
{
|
|
|
|
"name" => "rspec",
|
|
|
|
"size" => 2,
|
|
|
|
"jobs" =>
|
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
2021-01-13 07:10:27 -05:00
|
|
|
{
|
|
|
|
"name" => "rspec 0 1",
|
|
|
|
"groupName" => "rspec",
|
|
|
|
"stage" => "build",
|
|
|
|
"script" => ["rake spec"],
|
|
|
|
"beforeScript" => ["bundle install", "bundle exec rake db:create"],
|
|
|
|
"afterScript" => ["echo 'run this after'"],
|
|
|
|
"allowFailure" => false,
|
|
|
|
"only" => { "refs" => %w[branches master] },
|
|
|
|
"when" => "on_success",
|
|
|
|
"except" => nil,
|
|
|
|
"environment" => nil,
|
|
|
|
"tags" => %w[ruby postgres],
|
|
|
|
"needs" => { "nodes" => [] }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" => "rspec 0 2",
|
|
|
|
"groupName" => "rspec",
|
|
|
|
"stage" => "build",
|
|
|
|
"script" => ["rake spec"],
|
|
|
|
"beforeScript" => ["bundle install", "bundle exec rake db:create"],
|
|
|
|
"afterScript" => ["echo 'run this after'"],
|
|
|
|
"allowFailure" => true,
|
|
|
|
"only" => { "refs" => %w[branches tags] },
|
|
|
|
"when" => "on_failure",
|
|
|
|
"except" => nil,
|
|
|
|
"environment" => nil,
|
|
|
|
"tags" => [],
|
|
|
|
"needs" => { "nodes" => [] }
|
|
|
|
}
|
2020-12-21 16:10:23 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" => "spinach", "size" => 1, "jobs" =>
|
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
2021-01-13 07:10:27 -05:00
|
|
|
{
|
|
|
|
"name" => "spinach",
|
|
|
|
"groupName" => "spinach",
|
|
|
|
"stage" => "build",
|
|
|
|
"script" => ["rake spinach"],
|
|
|
|
"beforeScript" => ["bundle install", "bundle exec rake db:create"],
|
|
|
|
"afterScript" => ["echo 'run this after'"],
|
|
|
|
"allowFailure" => false,
|
|
|
|
"only" => { "refs" => %w[branches tags] },
|
|
|
|
"when" => "on_success",
|
|
|
|
"except" => { "refs" => ["tags"] },
|
|
|
|
"environment" => nil,
|
|
|
|
"tags" => [],
|
|
|
|
"needs" => { "nodes" => [] }
|
|
|
|
}
|
2020-12-21 16:10:23 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 13:09:55 -05:00
|
|
|
]
|
|
|
|
}
|
2020-12-21 16:10:23 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" => "test",
|
|
|
|
"groups" =>
|
2020-12-04 13:09:55 -05:00
|
|
|
{
|
2020-12-21 16:10:23 -05:00
|
|
|
"nodes" =>
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name" => "docker",
|
|
|
|
"size" => 1,
|
|
|
|
"jobs" =>
|
|
|
|
{
|
|
|
|
"nodes" => [
|
2021-01-13 07:10:27 -05:00
|
|
|
{
|
|
|
|
"name" => "docker",
|
|
|
|
"groupName" => "docker",
|
|
|
|
"stage" => "test",
|
|
|
|
"script" => ["curl http://dockerhub/URL"],
|
|
|
|
"beforeScript" => ["bundle install", "bundle exec rake db:create"],
|
|
|
|
"afterScript" => ["echo 'run this after'"],
|
|
|
|
"allowFailure" => true,
|
|
|
|
"only" => { "refs" => %w[branches tags] },
|
|
|
|
"when" => "manual",
|
|
|
|
"except" => { "refs" => ["branches"] },
|
|
|
|
"environment" => nil,
|
|
|
|
"tags" => [],
|
|
|
|
"needs" => { "nodes" => [{ "name" => "spinach" }, { "name" => "rspec 0 1" }] }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" => "deploy",
|
|
|
|
"groups" =>
|
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name" => "deploy_job",
|
|
|
|
"size" => 1,
|
|
|
|
"jobs" =>
|
|
|
|
{
|
|
|
|
"nodes" => [
|
|
|
|
{
|
|
|
|
"name" => "deploy_job",
|
|
|
|
"groupName" => "deploy_job",
|
|
|
|
"stage" => "deploy",
|
|
|
|
"script" => ["echo 'done'"],
|
|
|
|
"beforeScript" => ["bundle install", "bundle exec rake db:create"],
|
|
|
|
"afterScript" => ["echo 'run this after'"],
|
|
|
|
"allowFailure" => false,
|
|
|
|
"only" => { "refs" => %w[branches tags] },
|
|
|
|
"when" => "on_success",
|
|
|
|
"except" => nil,
|
|
|
|
"environment" => "production",
|
|
|
|
"tags" => [],
|
|
|
|
"needs" => { "nodes" => [] }
|
|
|
|
}
|
2020-12-21 16:10:23 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 13:09:55 -05:00
|
|
|
]
|
|
|
|
}
|
2020-12-21 16:10:23 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-12-04 13:09:55 -05:00
|
|
|
)
|
|
|
|
end
|
2020-12-25 04:10:31 -05:00
|
|
|
|
2022-01-04 07:13:46 -05:00
|
|
|
context 'when using deprecated keywords' do
|
|
|
|
let_it_be(:content) do
|
|
|
|
YAML.dump(
|
2022-01-20 13:14:18 -05:00
|
|
|
rspec: { script: 'ls', type: 'test' },
|
2022-01-04 07:13:46 -05:00
|
|
|
types: ['test']
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a warning' do
|
|
|
|
post_graphql_query
|
|
|
|
|
2022-01-20 13:14:18 -05:00
|
|
|
expect(graphql_data['ciConfig']['warnings']).to include(
|
|
|
|
'root `types` is deprecated in 9.0 and will be removed in 15.0.',
|
|
|
|
'jobs:rspec `type` is deprecated in 9.0 and will be removed in 15.0.'
|
|
|
|
)
|
2022-01-04 07:13:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-25 04:10:31 -05:00
|
|
|
context 'when the config file includes other files' do
|
|
|
|
let_it_be(:content) do
|
|
|
|
YAML.dump(
|
|
|
|
include: 'other_file.yml',
|
|
|
|
rspec: {
|
|
|
|
script: 'rspec'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Repository) do |repository|
|
|
|
|
allow(repository).to receive(:blob_data_at).with(an_instance_of(String), 'other_file.yml') do
|
|
|
|
YAML.dump(
|
|
|
|
build: {
|
|
|
|
script: 'build'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
post_graphql_query
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a working graphql query'
|
|
|
|
|
|
|
|
it 'returns the correct structure with included files' do
|
|
|
|
expect(graphql_data['ciConfig']).to eq(
|
|
|
|
"status" => "VALID",
|
|
|
|
"errors" => [],
|
2022-01-04 07:13:46 -05:00
|
|
|
"warnings" => [],
|
2020-12-25 04:10:31 -05:00
|
|
|
"stages" =>
|
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name" => "test",
|
|
|
|
"groups" =>
|
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name" => "build",
|
|
|
|
"size" => 1,
|
|
|
|
"jobs" =>
|
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
2021-01-13 07:10:27 -05:00
|
|
|
{
|
|
|
|
"name" => "build",
|
|
|
|
"stage" => "test",
|
|
|
|
"groupName" => "build",
|
|
|
|
"script" => ["build"],
|
|
|
|
"afterScript" => [],
|
|
|
|
"beforeScript" => [],
|
|
|
|
"allowFailure" => false,
|
|
|
|
"environment" => nil,
|
|
|
|
"except" => nil,
|
|
|
|
"only" => { "refs" => %w[branches tags] },
|
|
|
|
"when" => "on_success",
|
|
|
|
"tags" => [],
|
|
|
|
"needs" => { "nodes" => [] }
|
|
|
|
}
|
2020-12-25 04:10:31 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name" => "rspec",
|
|
|
|
"size" => 1,
|
|
|
|
"jobs" =>
|
|
|
|
{
|
|
|
|
"nodes" =>
|
|
|
|
[
|
2021-01-13 07:10:27 -05:00
|
|
|
{ "name" => "rspec",
|
|
|
|
"stage" => "test",
|
|
|
|
"groupName" => "rspec",
|
|
|
|
"script" => ["rspec"],
|
|
|
|
"afterScript" => [],
|
|
|
|
"beforeScript" => [],
|
|
|
|
"allowFailure" => false,
|
|
|
|
"environment" => nil,
|
|
|
|
"except" => nil,
|
|
|
|
"only" => { "refs" => %w[branches tags] },
|
|
|
|
"when" => "on_success",
|
|
|
|
"tags" => [],
|
|
|
|
"needs" => { "nodes" => [] } }
|
2020-12-25 04:10:31 -05:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-12-04 13:09:55 -05:00
|
|
|
end
|