PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/test/test_stash-repo-info.rb

https://bitbucket.org/zedenem/stash-command-line-tools
Ruby | 90 lines | 77 code | 13 blank | 0 comment | 0 complexity | aa45b3056bdec1e66ddf5441ebb45826 MD5 | raw file
  1. require 'helper'
  2. include Atlassian::Stash
  3. include Atlassian::Stash::Git
  4. class TestStashRepoInfo < Test::Unit::TestCase
  5. context "Extract repository info" do
  6. should "extract project key and repo slug from Stash remote" do
  7. remote = "https://sruiz@stash-dev.atlassian.com/scm/STASH/stash.git"
  8. ri = RepoInfo.create nil, remote
  9. assert_equal 'STASH', ri.projectKey
  10. assert_equal 'stash', ri.slug
  11. end
  12. should "extracting project key and repo slug from non stash url raises exception" do
  13. remote = "git@bitbucket.org:sebr/atlassian-stash-rubygem.git"
  14. assert_raise(RuntimeError) { RepoInfo.create nil, remote }
  15. end
  16. should "repo with hyphes" do
  17. remote = "https://sruiz@stash-dev.atlassian.com/scm/s745h/stash-repository.git"
  18. ri = RepoInfo.create nil, remote
  19. assert_equal 's745h', ri.projectKey
  20. assert_equal 'stash-repository', ri.slug
  21. end
  22. end
  23. context "Create repo url" do
  24. setup do
  25. @remote = "https://sruiz@stash-dev.atlassian.com/scm/STASH/stash.git"
  26. end
  27. should "create expected repo path" do
  28. config = {
  29. 'stash_url' => 'https://www.stash.com'
  30. }
  31. ri = RepoInfo.create config, @remote
  32. assert_equal '/projects/STASH/repos/stash', ri.repoPath
  33. end
  34. should "create expected repo path with context" do
  35. config = {
  36. 'stash_url' => 'https://www.stash.com/foo'
  37. }
  38. ri = RepoInfo.create config, @remote
  39. assert_equal '/foo/projects/STASH/repos/stash', ri.repoPath
  40. end
  41. should "create expected repo path with context and query" do
  42. config = {
  43. 'stash_url' => 'https://www.stash.com/foo'
  44. }
  45. ri = RepoInfo.create config, @remote
  46. assert_equal '/foo/projects/STASH/repos/stash', ri.repoPath
  47. end
  48. should "create expected repo url with no suffix or branch" do
  49. config = {
  50. 'stash_url' => 'https://www.stash.com'
  51. }
  52. ri = RepoInfo.create config, @remote
  53. assert_equal 'https://www.stash.com/projects/STASH/repos/stash', ri.repoUrl(nil, nil)
  54. end
  55. should "create expected repo url with context" do
  56. config = {
  57. 'stash_url' => 'https://www.stash.com/foo'
  58. }
  59. ri = RepoInfo.create config, @remote
  60. assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash', ri.repoUrl(nil, nil)
  61. end
  62. should "create expected repo url with path and branch" do
  63. config = {
  64. 'stash_url' => 'https://www.stash.com/foo'
  65. }
  66. ri = RepoInfo.create config, @remote
  67. assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash/commits?at=develop', ri.repoUrl('commits', 'develop')
  68. end
  69. should "create expected repo url with context, query, path and branch" do
  70. config = {
  71. 'stash_url' => 'https://www.stash.com/foo?git=ftw'
  72. }
  73. ri = RepoInfo.create config, @remote
  74. assert_equal 'https://www.stash.com/foo/projects/STASH/repos/stash/commits?git=ftw&at=develop', ri.repoUrl('commits', 'develop')
  75. end
  76. end
  77. end