You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package lfs
  4. import (
  5. "net/url"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func str2url(raw string) *url.URL {
  10. u, _ := url.Parse(raw)
  11. return u
  12. }
  13. func TestDetermineEndpoint(t *testing.T) {
  14. // Test cases
  15. cases := []struct {
  16. cloneurl string
  17. lfsurl string
  18. expected *url.URL
  19. }{
  20. // case 0
  21. {
  22. cloneurl: "",
  23. lfsurl: "",
  24. expected: nil,
  25. },
  26. // case 1
  27. {
  28. cloneurl: "https://git.com/repo",
  29. lfsurl: "",
  30. expected: str2url("https://git.com/repo.git/info/lfs"),
  31. },
  32. // case 2
  33. {
  34. cloneurl: "https://git.com/repo.git",
  35. lfsurl: "",
  36. expected: str2url("https://git.com/repo.git/info/lfs"),
  37. },
  38. // case 3
  39. {
  40. cloneurl: "",
  41. lfsurl: "https://gitlfs.com/repo",
  42. expected: str2url("https://gitlfs.com/repo"),
  43. },
  44. // case 4
  45. {
  46. cloneurl: "https://git.com/repo.git",
  47. lfsurl: "https://gitlfs.com/repo",
  48. expected: str2url("https://gitlfs.com/repo"),
  49. },
  50. // case 5
  51. {
  52. cloneurl: "git://git.com/repo.git",
  53. lfsurl: "",
  54. expected: str2url("https://git.com/repo.git/info/lfs"),
  55. },
  56. // case 6
  57. {
  58. cloneurl: "",
  59. lfsurl: "git://gitlfs.com/repo",
  60. expected: str2url("https://gitlfs.com/repo"),
  61. },
  62. }
  63. for n, c := range cases {
  64. ep := DetermineEndpoint(c.cloneurl, c.lfsurl)
  65. assert.Equal(t, c.expected, ep, "case %d: error should match", n)
  66. }
  67. }