2017-02-06 23:18:36 +08:00
|
|
|
// Copyright 2017 The Gitea 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 models
|
2016-04-23 06:28:08 +08:00
|
|
|
|
|
|
|
import (
|
2016-07-09 13:22:28 +08:00
|
|
|
"testing"
|
2016-04-23 06:28:08 +08:00
|
|
|
|
2021-09-19 19:49:59 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-11-19 21:39:57 +08:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-10 03:57:58 +08:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2021-11-12 22:36:47 +08:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 17:49:20 +08:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2017-09-17 01:17:57 +08:00
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2017-02-06 23:18:36 +08:00
|
|
|
|
2017-06-06 21:53:16 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-04-23 06:28:08 +08:00
|
|
|
)
|
|
|
|
|
2022-01-18 02:31:58 +08:00
|
|
|
func TestCheckRepoStats(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
assert.NoError(t, CheckRepoStats(db.DefaultContext))
|
|
|
|
}
|
|
|
|
|
2021-12-12 23:48:20 +08:00
|
|
|
func TestWatchRepo(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
const repoID = 3
|
|
|
|
const userID = 2
|
|
|
|
|
2022-05-20 22:08:52 +08:00
|
|
|
assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, true))
|
2021-12-12 23:48:20 +08:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID})
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID})
|
|
|
|
|
2022-05-20 22:08:52 +08:00
|
|
|
assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, false))
|
2021-12-12 23:48:20 +08:00
|
|
|
unittest.AssertNotExistsBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID})
|
|
|
|
unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID})
|
|
|
|
}
|
|
|
|
|
2019-11-25 00:34:44 +08:00
|
|
|
func TestMetas(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2019-11-25 00:34:44 +08:00
|
|
|
|
2021-12-10 09:27:50 +08:00
|
|
|
repo := &repo_model.Repository{Name: "testRepo"}
|
2021-11-24 17:49:20 +08:00
|
|
|
repo.Owner = &user_model.User{Name: "testOwner"}
|
2020-01-12 17:36:21 +08:00
|
|
|
repo.OwnerName = repo.Owner.Name
|
2017-02-08 14:29:07 +08:00
|
|
|
|
|
|
|
repo.Units = nil
|
2019-04-12 13:53:34 +08:00
|
|
|
|
|
|
|
metas := repo.ComposeMetas()
|
|
|
|
assert.Equal(t, "testRepo", metas["repo"])
|
|
|
|
assert.Equal(t, "testOwner", metas["user"])
|
2017-02-08 14:29:07 +08:00
|
|
|
|
2021-12-10 09:27:50 +08:00
|
|
|
externalTracker := repo_model.RepoUnit{
|
2021-11-10 03:57:58 +08:00
|
|
|
Type: unit.TypeExternalTracker,
|
2021-12-10 09:27:50 +08:00
|
|
|
Config: &repo_model.ExternalTrackerConfig{
|
2017-02-08 14:29:07 +08:00
|
|
|
ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
testSuccess := func(expectedStyle string) {
|
2021-12-10 09:27:50 +08:00
|
|
|
repo.Units = []*repo_model.RepoUnit{&externalTracker}
|
2019-11-25 00:34:44 +08:00
|
|
|
repo.RenderingMetas = nil
|
2017-02-08 14:29:07 +08:00
|
|
|
metas := repo.ComposeMetas()
|
|
|
|
assert.Equal(t, expectedStyle, metas["style"])
|
|
|
|
assert.Equal(t, "testRepo", metas["repo"])
|
|
|
|
assert.Equal(t, "testOwner", metas["user"])
|
|
|
|
assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
|
|
|
|
}
|
|
|
|
|
2017-09-17 01:17:57 +08:00
|
|
|
testSuccess(markup.IssueNameStyleNumeric)
|
2017-02-08 14:29:07 +08:00
|
|
|
|
2017-09-17 01:17:57 +08:00
|
|
|
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
|
|
|
|
testSuccess(markup.IssueNameStyleAlphanumeric)
|
2017-02-08 14:29:07 +08:00
|
|
|
|
2017-09-17 01:17:57 +08:00
|
|
|
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric
|
|
|
|
testSuccess(markup.IssueNameStyleNumeric)
|
2019-11-25 00:34:44 +08:00
|
|
|
|
2022-06-10 13:39:53 +08:00
|
|
|
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp
|
|
|
|
testSuccess(markup.IssueNameStyleRegexp)
|
|
|
|
|
2021-12-10 09:27:50 +08:00
|
|
|
repo, err := repo_model.GetRepositoryByID(3)
|
2019-11-25 00:34:44 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
metas = repo.ComposeMetas()
|
|
|
|
assert.Contains(t, metas, "org")
|
|
|
|
assert.Contains(t, metas, "teams")
|
2021-06-07 13:27:09 +08:00
|
|
|
assert.Equal(t, "user3", metas["org"])
|
|
|
|
assert.Equal(t, ",owners,team1,", metas["teams"])
|
2016-04-23 06:28:08 +08:00
|
|
|
}
|
2017-02-06 23:18:36 +08:00
|
|
|
|
2020-07-08 03:16:34 +08:00
|
|
|
func TestDoctorUserStarNum(t *testing.T) {
|
2021-11-12 22:36:47 +08:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2020-07-08 03:16:34 +08:00
|
|
|
|
|
|
|
assert.NoError(t, DoctorUserStarNum())
|
|
|
|
}
|