aboutsummaryrefslogtreecommitdiff
path: root/internal/db/repo_test.go
blob: f689f05db38681edc7195450cf137306509224af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package db

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"gogs.io/gogs/internal/markup"
)

func TestRepository_ComposeMetas(t *testing.T) {
	repo := &Repository{
		Name: "testrepo",
		Owner: &User{
			Name: "testuser",
		},
		ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
	}

	t.Run("no external tracker is configured", func(t *testing.T) {
		repo.EnableExternalTracker = false
		assert.Equal(t, map[string]string(nil), repo.ComposeMetas())

		// Should be nil even if other settings are present
		repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
		assert.Equal(t, map[string]string(nil), repo.ComposeMetas())
	})

	t.Run("an external issue tracker is configured", func(t *testing.T) {
		repo.EnableExternalTracker = true

		// Default to numeric issue style
		assert.Equal(t, markup.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
		repo.ExternalMetas = nil

		repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
		assert.Equal(t, markup.ISSUE_NAME_STYLE_NUMERIC, repo.ComposeMetas()["style"])
		repo.ExternalMetas = nil

		repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
		assert.Equal(t, markup.ISSUE_NAME_STYLE_ALPHANUMERIC, repo.ComposeMetas()["style"])
		repo.ExternalMetas = nil

		metas := repo.ComposeMetas()
		assert.Equal(t, "testuser", metas["user"])
		assert.Equal(t, "testrepo", metas["repo"])
		assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
	})
}