/spec/lib/gitlab/dependency_linker/godeps_json_linker_spec.rb

https://gitlab.com/artofhuman/gitlab-ce · Ruby · 84 lines · 74 code · 10 blank · 0 comment · 0 complexity · 30dfb9672872d85bf1ea72654ef2a663 MD5 · raw file

  1. require 'rails_helper'
  2. describe Gitlab::DependencyLinker::GodepsJsonLinker do
  3. describe '.support?' do
  4. it 'supports Godeps.json' do
  5. expect(described_class.support?('Godeps.json')).to be_truthy
  6. end
  7. it 'does not support other files' do
  8. expect(described_class.support?('Godeps.json.example')).to be_falsey
  9. end
  10. end
  11. describe '#link' do
  12. let(:file_name) { "Godeps.json" }
  13. let(:file_content) do
  14. <<-CONTENT.strip_heredoc
  15. {
  16. "ImportPath": "gitlab.com/gitlab-org/gitlab-pages",
  17. "GoVersion": "go1.5",
  18. "Packages": [
  19. "./..."
  20. ],
  21. "Deps": [
  22. {
  23. "ImportPath": "github.com/kardianos/osext",
  24. "Rev": "efacde03154693404c65e7aa7d461ac9014acd0c"
  25. },
  26. {
  27. "ImportPath": "github.com/stretchr/testify/assert",
  28. "Rev": "1297dc01ed0a819ff634c89707081a4df43baf6b"
  29. },
  30. {
  31. "ImportPath": "github.com/stretchr/testify/require",
  32. "Rev": "1297dc01ed0a819ff634c89707081a4df43baf6b"
  33. },
  34. {
  35. "ImportPath": "gitlab.com/group/project/path",
  36. "Rev": "1297dc01ed0a819ff634c89707081a4df43baf6b"
  37. },
  38. {
  39. "ImportPath": "gitlab.com/group/subgroup/project.git/path",
  40. "Rev": "1297dc01ed0a819ff634c89707081a4df43baf6b"
  41. },
  42. {
  43. "ImportPath": "golang.org/x/crypto/ssh/terminal",
  44. "Rev": "1351f936d976c60a0a48d728281922cf63eafb8d"
  45. },
  46. {
  47. "ImportPath": "golang.org/x/net/http2",
  48. "Rev": "b4e17d61b15679caf2335da776c614169a1b4643"
  49. }
  50. ]
  51. }
  52. CONTENT
  53. end
  54. subject { Gitlab::Highlight.highlight(file_name, file_content) }
  55. def link(name, url)
  56. %{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
  57. end
  58. it 'links the package name' do
  59. expect(subject).to include(link('gitlab.com/gitlab-org/gitlab-pages', 'https://gitlab.com/gitlab-org/gitlab-pages'))
  60. end
  61. it 'links GitHub repos' do
  62. expect(subject).to include(link('github.com/kardianos/osext', 'https://github.com/kardianos/osext'))
  63. expect(subject).to include(link('github.com/stretchr/testify/assert', 'https://github.com/stretchr/testify/tree/master/assert'))
  64. expect(subject).to include(link('github.com/stretchr/testify/require', 'https://github.com/stretchr/testify/tree/master/require'))
  65. end
  66. it 'links GitLab projects' do
  67. expect(subject).to include(link('gitlab.com/group/project/path', 'https://gitlab.com/group/project/tree/master/path'))
  68. expect(subject).to include(link('gitlab.com/group/subgroup/project.git/path', 'https://gitlab.com/group/subgroup/project/tree/master/path'))
  69. end
  70. it 'links Golang packages' do
  71. expect(subject).to include(link('golang.org/x/net/http2', 'https://godoc.org/golang.org/x/net/http2'))
  72. end
  73. end
  74. end