Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-18 15:07:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-18 15:07:48 +0300
commit79d62647bcfad69d7272020acb7d8be5ee5df003 (patch)
tree008d96a4c5fdfdecda79dae5e942c7df07511c77 /spec/lib/gitlab/dependency_linker
parent1a9d9cc14ec54036548824e3ce17da03960f5f81 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/dependency_linker')
-rw-r--r--spec/lib/gitlab/dependency_linker/cargo_toml_linker_spec.rb69
1 files changed, 69 insertions, 0 deletions
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