repo_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
  30. repo.ExternalMetas = nil
  31. repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
  32. assert.Equal(t, markup.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
  33. repo.ExternalMetas = nil
  34. repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
  35. assert.Equal(t, markup.ISSUE_NAME_STYLE_ALPHANUMERIC, 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. }