submodule_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package gitutil
  2. import (
  3. "testing"
  4. "github.com/gogs/git-module"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestInferSubmoduleURL(t *testing.T) {
  8. tests := []struct {
  9. name string
  10. submodule *git.Submodule
  11. expURL string
  12. }{
  13. {
  14. name: "HTTPS URL",
  15. submodule: &git.Submodule{
  16. URL: "https://github.com/gogs/docs-api.git",
  17. Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",
  18. },
  19. expURL: "https://github.com/gogs/docs-api/commit/6b08f76a5313fa3d26859515b30aa17a5faa2807",
  20. },
  21. {
  22. name: "SSH URL with port",
  23. submodule: &git.Submodule{
  24. URL: "ssh://user@github.com:22/gogs/docs-api.git",
  25. Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",
  26. },
  27. expURL: "http://github.com/gogs/docs-api/commit/6b08f76a5313fa3d26859515b30aa17a5faa2807",
  28. },
  29. {
  30. name: "SSH URL in SCP syntax",
  31. submodule: &git.Submodule{
  32. URL: "git@github.com:gogs/docs-api.git",
  33. Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",
  34. },
  35. expURL: "http://github.com/gogs/docs-api/commit/6b08f76a5313fa3d26859515b30aa17a5faa2807",
  36. },
  37. {
  38. name: "relative path",
  39. submodule: &git.Submodule{
  40. URL: "../repo2.git",
  41. Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",
  42. },
  43. expURL: "https://gogs.example.com/user/repo/../repo2/commit/6b08f76a5313fa3d26859515b30aa17a5faa2807",
  44. },
  45. {
  46. name: "bad URL",
  47. submodule: &git.Submodule{
  48. URL: "ftp://example.com",
  49. Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",
  50. },
  51. expURL: "ftp://example.com",
  52. },
  53. }
  54. for _, test := range tests {
  55. t.Run(test.name, func(t *testing.T) {
  56. assert.Equal(t, test.expURL, InferSubmoduleURL("https://gogs.example.com/user/repo", test.submodule))
  57. })
  58. }
  59. }