2017-12-08 06:22:02 +01: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 repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-11-12 15:36:47 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2017-12-08 06:22:02 +01:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
2021-01-26 16:36:53 +01:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-04-06 21:44:05 +02:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2017-12-08 06:22:02 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewReleasePost(t *testing.T) {
|
|
|
|
for _, testCase := range []struct {
|
|
|
|
RepoID int64
|
|
|
|
UserID int64
|
|
|
|
TagName string
|
2021-04-06 21:44:05 +02:00
|
|
|
Form forms.NewReleaseForm
|
2017-12-08 06:22:02 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
RepoID: 1,
|
|
|
|
UserID: 2,
|
|
|
|
TagName: "v1.1", // pre-existing tag
|
2021-04-06 21:44:05 +02:00
|
|
|
Form: forms.NewReleaseForm{
|
2017-12-08 06:22:02 +01:00
|
|
|
TagName: "newtag",
|
|
|
|
Target: "master",
|
|
|
|
Title: "title",
|
|
|
|
Content: "content",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
RepoID: 1,
|
|
|
|
UserID: 2,
|
|
|
|
TagName: "newtag",
|
2021-04-06 21:44:05 +02:00
|
|
|
Form: forms.NewReleaseForm{
|
2017-12-08 06:22:02 +01:00
|
|
|
TagName: "newtag",
|
|
|
|
Target: "master",
|
|
|
|
Title: "title",
|
|
|
|
Content: "content",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} {
|
2021-11-12 15:36:47 +01:00
|
|
|
unittest.PrepareTestEnv(t)
|
2017-12-08 06:22:02 +01: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 16:36:53 +01:00
|
|
|
web.SetForm(ctx, &testCase.Form)
|
|
|
|
NewReleasePost(ctx)
|
2021-11-16 09:53:21 +01:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &models.Release{
|
2017-12-08 06:22:02 +01:00
|
|
|
RepoID: 1,
|
|
|
|
PublisherID: 2,
|
|
|
|
TagName: testCase.Form.TagName,
|
|
|
|
Target: testCase.Form.Target,
|
|
|
|
Title: testCase.Form.Title,
|
|
|
|
Note: testCase.Form.Content,
|
2021-11-16 09:53:21 +01:00
|
|
|
}, unittest.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
|
2019-11-13 08:01:19 +01:00
|
|
|
ctx.Repo.GitRepo.Close()
|
2017-12-08 06:22:02 +01:00
|
|
|
}
|
|
|
|
}
|