2017-12-08 08:22:02 +03:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 21:20:29 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-12-08 08:22:02 +03:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-25 05:31:57 +03:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 17:36:47 +03:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2017-12-08 08:22:02 +03:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
2021-01-26 18:36:53 +03:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-04-06 22:44:05 +03:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2017-12-08 08:22:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewReleasePost(t *testing.T) {
|
|
|
|
for _, testCase := range []struct {
|
|
|
|
RepoID int64
|
|
|
|
UserID int64
|
|
|
|
TagName string
|
2021-04-06 22:44:05 +03:00
|
|
|
Form forms.NewReleaseForm
|
2017-12-08 08:22:02 +03:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
RepoID: 1,
|
|
|
|
UserID: 2,
|
|
|
|
TagName: "v1.1", // pre-existing tag
|
2021-04-06 22:44:05 +03:00
|
|
|
Form: forms.NewReleaseForm{
|
2017-12-08 08:22:02 +03:00
|
|
|
TagName: "newtag",
|
|
|
|
Target: "master",
|
|
|
|
Title: "title",
|
|
|
|
Content: "content",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
RepoID: 1,
|
|
|
|
UserID: 2,
|
|
|
|
TagName: "newtag",
|
2021-04-06 22:44:05 +03:00
|
|
|
Form: forms.NewReleaseForm{
|
2017-12-08 08:22:02 +03:00
|
|
|
TagName: "newtag",
|
|
|
|
Target: "master",
|
|
|
|
Title: "title",
|
|
|
|
Content: "content",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} {
|
2021-11-12 17:36:47 +03:00
|
|
|
unittest.PrepareTestEnv(t)
|
2017-12-08 08:22:02 +03:00
|
|
|
|
|
|
|
ctx := test.MockContext(t, "user2/repo1/releases/new")
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
test.LoadRepo(t, ctx, 1)
|
|
|
|
test.LoadGitRepo(t, ctx)
|
2021-01-26 18:36:53 +03:00
|
|
|
web.SetForm(ctx, &testCase.Form)
|
|
|
|
NewReleasePost(ctx)
|
2022-08-25 05:31:57 +03:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &repo_model.Release{
|
2017-12-08 08:22:02 +03:00
|
|
|
RepoID: 1,
|
|
|
|
PublisherID: 2,
|
|
|
|
TagName: testCase.Form.TagName,
|
|
|
|
Target: testCase.Form.Target,
|
|
|
|
Title: testCase.Form.Title,
|
|
|
|
Note: testCase.Form.Content,
|
2021-11-16 11:53:21 +03:00
|
|
|
}, unittest.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
|
2019-11-13 10:01:19 +03:00
|
|
|
ctx.Repo.GitRepo.Close()
|
2017-12-08 08:22:02 +03:00
|
|
|
}
|
|
|
|
}
|