diff options
Diffstat (limited to 'spec/requests/api/graphql/ci/config_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/ci/config_spec.rb | 144 |
1 files changed, 124 insertions, 20 deletions
diff --git a/spec/requests/api/graphql/ci/config_spec.rb b/spec/requests/api/graphql/ci/config_spec.rb index 62b15a8396c..5f8a895b16e 100644 --- a/spec/requests/api/graphql/ci/config_spec.rb +++ b/spec/requests/api/graphql/ci/config_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe 'Query.ciConfig' do include GraphqlHelpers + include StubRequests subject(:post_graphql_query) { post_graphql(query, current_user: user) } @@ -57,6 +58,16 @@ RSpec.describe 'Query.ciConfig' do } } } + mergedYaml + includes { + type + location + blob + raw + extra + contextProject + contextSha + } } } ) @@ -71,10 +82,12 @@ RSpec.describe 'Query.ciConfig' do it 'returns the correct structure' do post_graphql_query - expect(graphql_data['ciConfig']).to eq( + expect(graphql_data['ciConfig']).to include( "status" => "VALID", "errors" => [], "warnings" => [], + "includes" => [], + "mergedYaml" => a_kind_of(String), "stages" => { "nodes" => @@ -222,24 +235,6 @@ RSpec.describe 'Query.ciConfig' do ) end - context 'when using deprecated keywords' do - let_it_be(:content) do - YAML.dump( - rspec: { script: 'ls', type: 'test' }, - types: ['test'] - ) - end - - it 'returns a warning' do - post_graphql_query - - 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.' - ) - end - end - context 'when the config file includes other files' do let_it_be(:content) do YAML.dump( @@ -271,6 +266,18 @@ RSpec.describe 'Query.ciConfig' do "status" => "VALID", "errors" => [], "warnings" => [], + "includes" => [ + { + "type" => "local", + "location" => "other_file.yml", + "blob" => "http://localhost/#{project.full_path}/-/blob/#{project.commit.sha}/other_file.yml", + "raw" => "http://localhost/#{project.full_path}/-/raw/#{project.commit.sha}/other_file.yml", + "extra" => {}, + "contextProject" => project.full_path, + "contextSha" => project.commit.sha + } + ], + "mergedYaml" => "---\nbuild:\n script: build\nrspec:\n script: rspec\n", "stages" => { "nodes" => @@ -302,7 +309,7 @@ RSpec.describe 'Query.ciConfig' do "when" => "on_success", "tags" => [], "needs" => { "nodes" => [] } -} + } ] } }, @@ -337,4 +344,101 @@ RSpec.describe 'Query.ciConfig' do ) end end + + context 'when the config file has multiple includes' do + let_it_be(:other_project) { create(:project, :repository, creator: user, namespace: user.namespace) } + + let_it_be(:content) do + YAML.dump( + include: [ + { local: 'other_file.yml' }, + { remote: 'https://gitlab.com/gitlab-org/gitlab/raw/1234/.hello.yml' }, + { file: 'other_project_file.yml', project: other_project.full_path }, + { template: 'Jobs/Build.gitlab-ci.yml' } + ], + rspec: { + script: 'rspec' + } + ) + end + + let(:remote_file_content) do + YAML.dump( + remote_file_test: { + script: 'remote_file_test' + } + ) + 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 + + allow(repository).to receive(:blob_data_at).with(an_instance_of(String), 'other_project_file.yml') do + YAML.dump( + other_project_test: { + script: 'other_project_test' + } + ) + end + end + + stub_full_request('https://gitlab.com/gitlab-org/gitlab/raw/1234/.hello.yml').to_return(body: remote_file_content) + + post_graphql_query + end + + it_behaves_like 'a working graphql query' + + # rubocop:disable Layout/LineLength + it 'returns correct includes' do + expect(graphql_data['ciConfig']["includes"]).to eq( + [ + { + "type" => "local", + "location" => "other_file.yml", + "blob" => "http://localhost/#{project.full_path}/-/blob/#{project.commit.sha}/other_file.yml", + "raw" => "http://localhost/#{project.full_path}/-/raw/#{project.commit.sha}/other_file.yml", + "extra" => {}, + "contextProject" => project.full_path, + "contextSha" => project.commit.sha + }, + { + "type" => "remote", + "location" => "https://gitlab.com/gitlab-org/gitlab/raw/1234/.hello.yml", + "blob" => nil, + "raw" => "https://gitlab.com/gitlab-org/gitlab/raw/1234/.hello.yml", + "extra" => {}, + "contextProject" => project.full_path, + "contextSha" => project.commit.sha + }, + { + "type" => "file", + "location" => "other_project_file.yml", + "blob" => "http://localhost/#{other_project.full_path}/-/blob/#{other_project.commit.sha}/other_project_file.yml", + "raw" => "http://localhost/#{other_project.full_path}/-/raw/#{other_project.commit.sha}/other_project_file.yml", + "extra" => { "project" => other_project.full_path, "ref" => "HEAD" }, + "contextProject" => project.full_path, + "contextSha" => project.commit.sha + }, + { + "type" => "template", + "location" => "Jobs/Build.gitlab-ci.yml", + "blob" => nil, + "raw" => "https://gitlab.com/gitlab-org/gitlab/-/raw/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml", + "extra" => {}, + "contextProject" => project.full_path, + "contextSha" => project.commit.sha + } + ] + ) + end + # rubocop:enable Layout/LineLength + end end |