1
0

repo_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2022 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 and LICENSE.gogs file.
  4. // Copyright 2025 Huan-Gogs Authors. All rights reserved.
  5. // Use of this source code is governed by a MIT-style
  6. // license that can be found in the LICENSE file.
  7. package database
  8. import (
  9. "testing"
  10. "github.com/stretchr/testify/assert"
  11. "github.com/SongZihuan/huan-gogs/internal/markup"
  12. )
  13. func TestRepository_ComposeMetas(t *testing.T) {
  14. repo := &Repository{
  15. Name: "testrepo",
  16. Owner: &User{
  17. Name: "testuser",
  18. },
  19. ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
  20. }
  21. t.Run("no external tracker is configured", func(t *testing.T) {
  22. repo.EnableExternalTracker = false
  23. metas := repo.ComposeMetas()
  24. assert.Equal(t, metas["repoLink"], repo.Link())
  25. // Should no format and style if no external tracker is configured
  26. _, ok := metas["format"]
  27. assert.False(t, ok)
  28. _, ok = metas["style"]
  29. assert.False(t, ok)
  30. })
  31. t.Run("an external issue tracker is configured", func(t *testing.T) {
  32. repo.ExternalMetas = nil
  33. repo.EnableExternalTracker = true
  34. // Default to numeric issue style
  35. assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
  36. repo.ExternalMetas = nil
  37. repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
  38. assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
  39. repo.ExternalMetas = nil
  40. repo.ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
  41. assert.Equal(t, markup.IssueNameStyleAlphanumeric, repo.ComposeMetas()["style"])
  42. repo.ExternalMetas = nil
  43. metas := repo.ComposeMetas()
  44. assert.Equal(t, "testuser", metas["user"])
  45. assert.Equal(t, "testrepo", metas["repo"])
  46. assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
  47. })
  48. }