2
0

submodule_test.go 1.8 KB

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