summaryrefslogtreecommitdiffstats
path: root/models/repo/repo_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo/repo_test.go')
-rw-r--r--models/repo/repo_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/models/repo/repo_test.go b/models/repo/repo_test.go
index 8ae84eab52..6f8b282a66 100644
--- a/models/repo/repo_test.go
+++ b/models/repo/repo_test.go
@@ -9,7 +9,10 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
@@ -57,3 +60,68 @@ func TestRepoAPIURL(t *testing.T) {
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL())
}
+
+func TestWatchRepo(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ const repoID = 3
+ const userID = 2
+
+ assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, true))
+ unittest.AssertExistsAndLoadBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID})
+ unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID})
+
+ assert.NoError(t, repo_model.WatchRepo(db.DefaultContext, userID, repoID, false))
+ unittest.AssertNotExistsBean(t, &repo_model.Watch{RepoID: repoID, UserID: userID})
+ unittest.CheckConsistencyFor(t, &repo_model.Repository{ID: repoID})
+}
+
+func TestMetas(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ repo := &repo_model.Repository{Name: "testRepo"}
+ repo.Owner = &user_model.User{Name: "testOwner"}
+ repo.OwnerName = repo.Owner.Name
+
+ repo.Units = nil
+
+ metas := repo.ComposeMetas()
+ assert.Equal(t, "testRepo", metas["repo"])
+ assert.Equal(t, "testOwner", metas["user"])
+
+ externalTracker := repo_model.RepoUnit{
+ Type: unit.TypeExternalTracker,
+ Config: &repo_model.ExternalTrackerConfig{
+ ExternalTrackerFormat: "https://someurl.com/{user}/{repo}/{issue}",
+ },
+ }
+
+ testSuccess := func(expectedStyle string) {
+ repo.Units = []*repo_model.RepoUnit{&externalTracker}
+ repo.RenderingMetas = nil
+ 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"])
+ }
+
+ testSuccess(markup.IssueNameStyleNumeric)
+
+ externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
+ testSuccess(markup.IssueNameStyleAlphanumeric)
+
+ externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric
+ testSuccess(markup.IssueNameStyleNumeric)
+
+ externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleRegexp
+ testSuccess(markup.IssueNameStyleRegexp)
+
+ repo, err := repo_model.GetRepositoryByID(3)
+ assert.NoError(t, err)
+
+ metas = repo.ComposeMetas()
+ assert.Contains(t, metas, "org")
+ assert.Contains(t, metas, "teams")
+ assert.Equal(t, "user3", metas["org"])
+ assert.Equal(t, ",owners,team1,", metas["teams"])
+}