summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-18 12:07:48 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-18 12:07:48 +0000
commit79d62647bcfad69d7272020acb7d8be5ee5df003 (patch)
tree008d96a4c5fdfdecda79dae5e942c7df07511c77 /spec/lib
parent1a9d9cc14ec54036548824e3ce17da03960f5f81 (diff)
downloadgitlab-ce-79d62647bcfad69d7272020acb7d8be5ee5df003.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb73
-rw-r--r--spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb50
-rw-r--r--spec/lib/gitlab/dependency_linker/cargo_toml_linker_spec.rb69
-rw-r--r--spec/lib/gitlab/dependency_linker_spec.rb8
-rw-r--r--spec/lib/sentry/client/issue_spec.rb79
-rw-r--r--spec/lib/sentry/client_spec.rb12
6 files changed, 269 insertions, 22 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb
index 7ebe5842fd0..f84f10bdc46 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb
@@ -40,7 +40,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
subject.perform!
expect(pipeline.config_source).to eq 'auto_devops_source'
- template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps')
+ template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps')
expect(command.config_content).to eq(template.content)
end
end
@@ -52,7 +52,7 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
subject.perform!
expect(pipeline.config_source).to eq 'auto_devops_source'
- template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps')
+ template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps')
expect(command.config_content).to eq(template.content)
end
end
@@ -82,12 +82,32 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
expect(project).to receive(:auto_devops_enabled?).and_return(true)
end
- it 'returns the content of AutoDevops template' do
- subject.perform!
+ context 'when beta is enabled' do
+ before do
+ stub_feature_flags(auto_devops_beta: true)
+ end
- expect(pipeline.config_source).to eq 'auto_devops_source'
- template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps')
- expect(command.config_content).to eq(template.content)
+ it 'returns the content of AutoDevops template' do
+ subject.perform!
+
+ expect(pipeline.config_source).to eq 'auto_devops_source'
+ template = Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps')
+ expect(command.config_content).to eq(template.content)
+ end
+ end
+
+ context 'when beta is disabled' do
+ before do
+ stub_feature_flags(auto_devops_beta: false)
+ end
+
+ it 'returns the content of AutoDevops template' do
+ subject.perform!
+
+ expect(pipeline.config_source).to eq 'auto_devops_source'
+ template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps')
+ expect(command.config_content).to eq(template.content)
+ end
end
end
@@ -190,15 +210,38 @@ describe Gitlab::Ci::Pipeline::Chain::Config::Content do
expect(project).to receive(:auto_devops_enabled?).and_return(true)
end
- it 'builds root config including the auto-devops template' do
- subject.perform!
+ context 'when beta is enabled' do
+ before do
+ stub_feature_flags(auto_devops_beta: true)
+ end
- expect(pipeline.config_source).to eq 'auto_devops_source'
- expect(command.config_content).to eq(<<~EOY)
- ---
- include:
- - template: Auto-DevOps.gitlab-ci.yml
- EOY
+ it 'builds root config including the auto-devops template' do
+ subject.perform!
+
+ expect(pipeline.config_source).to eq 'auto_devops_source'
+ expect(command.config_content).to eq(<<~EOY)
+ ---
+ include:
+ - template: Beta/Auto-DevOps.gitlab-ci.yml
+ EOY
+ end
+ end
+
+ context 'when beta is disabled' do
+ before do
+ stub_feature_flags(auto_devops_beta: false)
+ end
+
+ it 'builds root config including the auto-devops template' do
+ subject.perform!
+
+ expect(pipeline.config_source).to eq 'auto_devops_source'
+ expect(command.config_content).to eq(<<~EOY)
+ ---
+ include:
+ - template: Auto-DevOps.gitlab-ci.yml
+ EOY
+ end
end
end
diff --git a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb
index c2f9930056a..12600d97b2f 100644
--- a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb
@@ -9,7 +9,7 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
let(:user) { create(:admin) }
let(:default_branch) { 'master' }
let(:pipeline_branch) { default_branch }
- let(:project) { create(:project, :custom_repo, files: { 'README.md' => '' }) }
+ let(:project) { create(:project, :auto_devops, :custom_repo, files: { 'README.md' => '' }) }
let(:service) { Ci::CreatePipelineService.new(project, user, ref: pipeline_branch ) }
let(:pipeline) { service.execute!(:push) }
let(:build_names) { pipeline.builds.pluck(:name) }
@@ -107,4 +107,52 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
end
end
end
+
+ describe 'build-pack detection' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:case_name, :files, :variables, :include_build_names, :not_include_build_names) do
+ 'No match' | { 'README.md' => '' } | {} | %w() | %w(build test)
+ 'Buildpack' | { 'README.md' => '' } | { 'BUILDPACK_URL' => 'http://example.com' } | %w(build test) | %w()
+ 'Explicit set' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '1' } | %w(build test) | %w()
+ 'Explicit unset' | { 'README.md' => '' } | { 'AUTO_DEVOPS_EXPLICITLY_ENABLED' => '0' } | %w() | %w(build test)
+ 'Dockerfile' | { 'Dockerfile' => '' } | {} | %w(build test) | %w()
+ 'Clojure' | { 'project.clj' => '' } | {} | %w(build test) | %w()
+ 'Go modules' | { 'go.mod' => '' } | {} | %w(build test) | %w()
+ 'Go gb' | { 'src/gitlab.com/gopackage.go' => '' } | {} | %w(build test) | %w()
+ 'Gradle' | { 'gradlew' => '' } | {} | %w(build test) | %w()
+ 'Java' | { 'pom.xml' => '' } | {} | %w(build test) | %w()
+ 'Multi-buildpack' | { '.buildpacks' => '' } | {} | %w(build test) | %w()
+ 'NodeJS' | { 'package.json' => '' } | {} | %w(build test) | %w()
+ 'PHP' | { 'composer.json' => '' } | {} | %w(build test) | %w()
+ 'Play' | { 'conf/application.conf' => '' } | {} | %w(build test) | %w()
+ 'Python' | { 'Pipfile' => '' } | {} | %w(build test) | %w()
+ 'Ruby' | { 'Gemfile' => '' } | {} | %w(build test) | %w()
+ 'Scala' | { 'build.sbt' => '' } | {} | %w(build test) | %w()
+ 'Static' | { '.static' => '' } | {} | %w(build test) | %w()
+ end
+
+ with_them do
+ subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Beta/Auto-DevOps') }
+
+ let(:user) { create(:admin) }
+ let(:project) { create(:project, :custom_repo, files: files) }
+ let(:service) { Ci::CreatePipelineService.new(project, user, ref: 'master' ) }
+ let(:pipeline) { service.execute(:push) }
+ let(:build_names) { pipeline.builds.pluck(:name) }
+
+ before do
+ stub_ci_pipeline_yaml_file(template.content)
+ allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true)
+ variables.each do |(key, value)|
+ create(:ci_variable, project: project, key: key, value: value)
+ end
+ end
+
+ it 'creates a pipeline with the expected jobs' do
+ expect(build_names).to include(*include_build_names)
+ expect(build_names).not_to include(*not_include_build_names)
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/dependency_linker/cargo_toml_linker_spec.rb b/spec/lib/gitlab/dependency_linker/cargo_toml_linker_spec.rb
new file mode 100644
index 00000000000..86d5bc93bf7
--- /dev/null
+++ b/spec/lib/gitlab/dependency_linker/cargo_toml_linker_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::DependencyLinker::CargoTomlLinker do
+ describe '.support?' do
+ it 'supports Cargo.toml' do
+ expect(described_class.support?('Cargo.toml')).to be_truthy
+ end
+
+ it 'does not support other files' do
+ expect(described_class.support?('cargo.yaml')).to be_falsey
+ end
+ end
+
+ describe '#link' do
+ let(:file_name) { "Cargo.toml" }
+
+ let(:file_content) do
+ <<-CONTENT.strip_heredoc
+ # See https://doc.rust-lang.org/cargo/reference/manifest.html
+ [package]
+ # Package shouldn't be matched
+ name = "gitlab-test"
+ version = "0.0.1"
+ authors = ["Some User <some.user@example.org>"]
+ description = "A GitLab test Cargo.toml."
+ keywords = ["gitlab", "test", "rust", "crago"]
+ readme = "README.md"
+
+ [dependencies]
+ # Default dependencies format with fixed version and version range
+ chrono = "0.4.7"
+ xml-rs = ">=0.8.0"
+
+ [dependencies.memchr]
+ # Specific dependency with optional info
+ version = "2.2.1"
+ optional = true
+
+ [dev-dependencies]
+ # Dev dependency with version modifier
+ commandspec = "~0.12.2"
+
+ [build-dependencies]
+ # Build dependency with version wildcard
+ thread_local = "0.3.*"
+ CONTENT
+ end
+
+ subject { Gitlab::Highlight.highlight(file_name, file_content) }
+
+ def link(name, url)
+ %{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
+ end
+
+ it 'links dependencies' do
+ expect(subject).to include(link('chrono', 'https://crates.io/crates/chrono'))
+ expect(subject).to include(link('xml-rs', 'https://crates.io/crates/xml-rs'))
+ expect(subject).to include(link('memchr', 'https://crates.io/crates/memchr'))
+ expect(subject).to include(link('commandspec', 'https://crates.io/crates/commandspec'))
+ expect(subject).to include(link('thread_local', 'https://crates.io/crates/thread_local'))
+ end
+
+ it 'does not contain metadata identified as package' do
+ expect(subject).not_to include(link('version', 'https://crates.io/crates/version'))
+ end
+ end
+end
diff --git a/spec/lib/gitlab/dependency_linker_spec.rb b/spec/lib/gitlab/dependency_linker_spec.rb
index 3ea3334caf0..570a994f520 100644
--- a/spec/lib/gitlab/dependency_linker_spec.rb
+++ b/spec/lib/gitlab/dependency_linker_spec.rb
@@ -83,5 +83,13 @@ describe Gitlab::DependencyLinker do
described_class.link(blob_name, nil, nil)
end
+
+ it 'links using CargoTomlLinker' do
+ blob_name = 'Cargo.toml'
+
+ expect(described_class::CargoTomlLinker).to receive(:link)
+
+ described_class.link(blob_name, nil, nil)
+ end
end
end
diff --git a/spec/lib/sentry/client/issue_spec.rb b/spec/lib/sentry/client/issue_spec.rb
new file mode 100644
index 00000000000..17548e2081d
--- /dev/null
+++ b/spec/lib/sentry/client/issue_spec.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Sentry::Client::Issue do
+ include SentryClientHelpers
+
+ let(:token) { 'test-token' }
+ let(:client) { Sentry::Client.new(sentry_url, token) }
+
+ describe '#issue_details' do
+ let(:issue_sample_response) do
+ Gitlab::Utils.deep_indifferent_access(
+ JSON.parse(fixture_file('sentry/issue_sample_response.json'))
+ )
+ end
+
+ let(:issue_id) { 503504 }
+ let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0' }
+ let(:sentry_request_url) { "#{sentry_url}/issues/#{issue_id}/" }
+ let!(:sentry_api_request) { stub_sentry_request(sentry_request_url, body: issue_sample_response) }
+
+ subject { client.issue_details(issue_id: issue_id) }
+
+ it_behaves_like 'calls sentry api'
+
+ it 'escapes issue ID' do
+ allow(CGI).to receive(:escape).and_call_original
+
+ subject
+
+ expect(CGI).to have_received(:escape).with(issue_id.to_s)
+ end
+
+ context 'error object created from sentry response' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:error_object, :sentry_response) do
+ :id | :id
+ :first_seen | :firstSeen
+ :last_seen | :lastSeen
+ :title | :title
+ :type | :type
+ :user_count | :userCount
+ :count | :count
+ :message | [:metadata, :value]
+ :culprit | :culprit
+ :short_id | :shortId
+ :status | :status
+ :frequency | [:stats, '24h']
+ :project_id | [:project, :id]
+ :project_name | [:project, :name]
+ :project_slug | [:project, :slug]
+ :first_release_last_commit | [:firstRelease, :lastCommit]
+ :last_release_last_commit | [:lastRelease, :lastCommit]
+ :first_release_short_version | [:firstRelease, :shortVersion]
+ :last_release_short_version | [:lastRelease, :shortVersion]
+ end
+
+ with_them do
+ it do
+ expect(subject.public_send(error_object)).to eq(issue_sample_response.dig(*sentry_response))
+ end
+ end
+
+ it 'has a correct external URL' do
+ expect(subject.external_url).to eq('https://sentrytest.gitlab.com/api/0/issues/503504')
+ end
+
+ it 'issue has a correct external base url' do
+ expect(subject.external_base_url).to eq('https://sentrytest.gitlab.com/api/0')
+ end
+
+ it 'has a correct GitLab issue url' do
+ expect(subject.gitlab_issue).to eq('https://gitlab.com/gitlab-org/gitlab/issues/1')
+ end
+ end
+ end
+end
diff --git a/spec/lib/sentry/client_spec.rb b/spec/lib/sentry/client_spec.rb
index cff06bf4a5f..8500f67b8e9 100644
--- a/spec/lib/sentry/client_spec.rb
+++ b/spec/lib/sentry/client_spec.rb
@@ -14,12 +14,6 @@ describe Sentry::Client do
}
end
- let(:issues_sample_response) do
- Gitlab::Utils.deep_indifferent_access(
- JSON.parse(fixture_file('sentry/issues_sample_response.json'))
- )
- end
-
subject(:client) { described_class.new(sentry_url, token) }
shared_examples 'issues has correct return type' do |klass|
@@ -33,6 +27,12 @@ describe Sentry::Client do
end
describe '#list_issues' do
+ let(:issues_sample_response) do
+ Gitlab::Utils.deep_indifferent_access(
+ JSON.parse(fixture_file('sentry/issues_sample_response.json'))
+ )
+ end
+
let(:issue_status) { 'unresolved' }
let(:limit) { 20 }
let(:search_term) { '' }