repo_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package db
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "gogs.io/gogs/internal/markup"
  6. )
  7. func TestRepository_ComposeMetas(t *testing.T) {
  8. repo := &Repository{
  9. Name: "testrepo",
  10. Owner: &User{
  11. Name: "testuser",
  12. },
  13. ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
  14. }
  15. t.Run("no external tracker is configured", func(t *testing.T) {
  16. repo.EnableExternalTracker = false
  17. metas := repo.ComposeMetas()
  18. assert.Equal(t, metas["repoLink"], repo.Link())
  19. // Should no format and style if no external tracker is configured
  20. _, ok := metas["format"]
  21. assert.False(t, ok)
  22. _, ok = metas["style"]
  23. assert.False(t, ok)
  24. })
  25. t.Run("an external issue tracker is configured", func(t *testing.T) {
  26. repo.ExternalMetas = nil
  27. repo.EnableExternalTracker = true
  28. // Default to numeric issue style
  29. assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
  30. repo.ExternalMetas = nil
  31. repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
  32. assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
  33. repo.ExternalMetas = nil
  34. repo.ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
  35. assert.Equal(t, markup.IssueNameStyleAlphanumeric, repo.ComposeMetas()["style"])
  36. repo.ExternalMetas = nil
  37. metas := repo.ComposeMetas()
  38. assert.Equal(t, "testuser", metas["user"])
  39. assert.Equal(t, "testrepo", metas["repo"])
  40. assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
  41. })
  42. }