submodule_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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: "bad URL",
  42. submodule: &git.Submodule{
  43. URL: "ftp://example.com",
  44. Commit: "6b08f76a5313fa3d26859515b30aa17a5faa2807",
  45. },
  46. expURL: "ftp://example.com",
  47. },
  48. }
  49. for _, test := range tests {
  50. t.Run(test.name, func(t *testing.T) {
  51. assert.Equal(t, test.expURL, InferSubmoduleURL(test.submodule))
  52. })
  53. }
  54. }