本站源代码
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

41 linhas
2.1KB

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestGetRefURL(t *testing.T) {
  10. var kases = []struct {
  11. refURL string
  12. prefixURL string
  13. parentPath string
  14. expect string
  15. }{
  16. {"git://github.com/user1/repo1", "/", "/", "http://github.com/user1/repo1"},
  17. {"https://localhost/user1/repo1.git", "/", "/", "https://localhost/user1/repo1"},
  18. {"http://localhost/user1/repo1.git", "/", "/", "http://localhost/user1/repo1"},
  19. {"git@github.com:user1/repo1.git", "/", "/", "http://github.com/user1/repo1"},
  20. {"ssh://git@git.zefie.net:2222/zefie/lge_g6_kernel_scripts.git", "/", "/", "http://git.zefie.net/zefie/lge_g6_kernel_scripts"},
  21. {"git@git.zefie.net:2222/zefie/lge_g6_kernel_scripts.git", "/", "/", "http://git.zefie.net/2222/zefie/lge_g6_kernel_scripts"},
  22. {"git@try.gitea.io:go-gitea/gitea", "https://try.gitea.io/go-gitea/gitea", "/", "https://try.gitea.io/go-gitea/gitea"},
  23. {"ssh://git@try.gitea.io:9999/go-gitea/gitea", "https://try.gitea.io/go-gitea/gitea", "/", "https://try.gitea.io/go-gitea/gitea"},
  24. {"git://git@try.gitea.io:9999/go-gitea/gitea", "https://try.gitea.io/go-gitea/log", "/", "https://try.gitea.io/go-gitea/gitea"},
  25. {"ssh://git@127.0.0.1:9999/go-gitea/gitea", "https://127.0.0.1:3000/go-gitea/log", "/", "https://127.0.0.1:3000/go-gitea/gitea"},
  26. {"https://gitea.com:3000/user1/repo1.git", "https://127.0.0.1:3000/go-gitea/gitea", "/", "https://gitea.com:3000/user1/repo1"},
  27. {"https://username:password@github.com/username/repository.git", "/", "/", "https://username:password@github.com/username/repository"},
  28. {"somethingbad", "https://127.0.0.1:3000/go-gitea/gitea", "/", ""},
  29. {"git@localhost:user/repo", "https://localhost/user/repo2", "/", "https://localhost/user/repo"},
  30. {"../path/to/repo.git/", "https://localhost/user/repo2/src/branch/master/test", "/", "../path/to/repo.git/"},
  31. }
  32. for _, kase := range kases {
  33. assert.EqualValues(t, kase.expect, getRefURL(kase.refURL, kase.prefixURL, kase.parentPath))
  34. }
  35. }
上海开阖软件有限公司 沪ICP备12045867号-1