1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- // Copyright 2022 The Gogs Authors. All rights reserved.
- // Use of this source code is governed by a MIT-style
- // license that can be found in the LICENSE and LICENSE.gogs file.
- // Copyright 2025 Huan-Gogs Authors. All rights reserved.
- // Use of this source code is governed by a MIT-style
- // license that can be found in the LICENSE file.
- package database
- import (
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/SongZihuan/huan-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
- metas := repo.ComposeMetas()
- assert.Equal(t, metas["repoLink"], repo.Link())
- // Should no format and style if no external tracker is configured
- _, ok := metas["format"]
- assert.False(t, ok)
- _, ok = metas["style"]
- assert.False(t, ok)
- })
- t.Run("an external issue tracker is configured", func(t *testing.T) {
- repo.ExternalMetas = nil
- repo.EnableExternalTracker = true
- // Default to numeric issue style
- assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
- repo.ExternalMetas = nil
- repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
- assert.Equal(t, markup.IssueNameStyleNumeric, repo.ComposeMetas()["style"])
- repo.ExternalMetas = nil
- repo.ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
- assert.Equal(t, markup.IssueNameStyleAlphanumeric, 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"])
- })
- }
|