2017-12-08 10:52:02 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-12-08 10:52:02 +05:30
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-25 08:01:57 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2017-12-08 10:52:02 +05:30
|
|
|
"code.gitea.io/gitea/modules/test"
|
2021-01-26 21:06:53 +05:30
|
|
|
"code.gitea.io/gitea/modules/web"
|
2021-04-07 01:14:05 +05:30
|
|
|
"code.gitea.io/gitea/services/forms"
|
2023-05-10 09:13:55 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-12-08 10:52:02 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewReleasePost(t *testing.T) {
|
|
|
|
for _, testCase := range []struct {
|
|
|
|
RepoID int64
|
|
|
|
UserID int64
|
|
|
|
TagName string
|
2021-04-07 01:14:05 +05:30
|
|
|
Form forms.NewReleaseForm
|
2017-12-08 10:52:02 +05:30
|
|
|
}{
|
|
|
|
{
|
|
|
|
RepoID: 1,
|
|
|
|
UserID: 2,
|
|
|
|
TagName: "v1.1", // pre-existing tag
|
2021-04-07 01:14:05 +05:30
|
|
|
Form: forms.NewReleaseForm{
|
2017-12-08 10:52:02 +05:30
|
|
|
TagName: "newtag",
|
|
|
|
Target: "master",
|
|
|
|
Title: "title",
|
|
|
|
Content: "content",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
RepoID: 1,
|
|
|
|
UserID: 2,
|
|
|
|
TagName: "newtag",
|
2021-04-07 01:14:05 +05:30
|
|
|
Form: forms.NewReleaseForm{
|
2017-12-08 10:52:02 +05:30
|
|
|
TagName: "newtag",
|
|
|
|
Target: "master",
|
|
|
|
Title: "title",
|
|
|
|
Content: "content",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} {
|
2021-11-12 20:06:47 +05:30
|
|
|
unittest.PrepareTestEnv(t)
|
2017-12-08 10:52:02 +05:30
|
|
|
|
|
|
|
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 21:06:53 +05:30
|
|
|
web.SetForm(ctx, &testCase.Form)
|
|
|
|
NewReleasePost(ctx)
|
2022-08-25 08:01:57 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &repo_model.Release{
|
2017-12-08 10:52:02 +05:30
|
|
|
RepoID: 1,
|
|
|
|
PublisherID: 2,
|
|
|
|
TagName: testCase.Form.TagName,
|
|
|
|
Target: testCase.Form.Target,
|
|
|
|
Title: testCase.Form.Title,
|
|
|
|
Note: testCase.Form.Content,
|
2021-11-16 14:23:21 +05:30
|
|
|
}, unittest.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
|
2019-11-13 12:31:19 +05:30
|
|
|
ctx.Repo.GitRepo.Close()
|
2017-12-08 10:52:02 +05:30
|
|
|
}
|
|
|
|
}
|
2023-05-10 09:13:55 +05:30
|
|
|
|
|
|
|
func TestNewReleasesList(t *testing.T) {
|
|
|
|
unittest.PrepareTestEnv(t)
|
|
|
|
ctx := test.MockContext(t, "user2/repo-release/releases")
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
test.LoadRepo(t, ctx, 57)
|
|
|
|
test.LoadGitRepo(t, ctx)
|
|
|
|
t.Cleanup(func() { ctx.Repo.GitRepo.Close() })
|
|
|
|
|
|
|
|
Releases(ctx)
|
|
|
|
releases := ctx.Data["Releases"].([]*repo_model.Release)
|
|
|
|
type computedFields struct {
|
|
|
|
NumCommitsBehind int64
|
|
|
|
TargetBehind string
|
|
|
|
}
|
|
|
|
expectedComputation := map[string]computedFields{
|
|
|
|
"v1.0": {
|
|
|
|
NumCommitsBehind: 3,
|
|
|
|
TargetBehind: "main",
|
|
|
|
},
|
|
|
|
"v1.1": {
|
|
|
|
NumCommitsBehind: 1,
|
|
|
|
TargetBehind: "main",
|
|
|
|
},
|
|
|
|
"v2.0": {
|
|
|
|
NumCommitsBehind: 0,
|
|
|
|
TargetBehind: "main",
|
|
|
|
},
|
|
|
|
"non-existing-target-branch": {
|
|
|
|
NumCommitsBehind: 1,
|
|
|
|
TargetBehind: "main",
|
|
|
|
},
|
|
|
|
"empty-target-branch": {
|
|
|
|
NumCommitsBehind: 1,
|
|
|
|
TargetBehind: "main",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, r := range releases {
|
|
|
|
actual := computedFields{
|
|
|
|
NumCommitsBehind: r.NumCommitsBehind,
|
|
|
|
TargetBehind: r.TargetBehind,
|
|
|
|
}
|
|
|
|
assert.Equal(t, expectedComputation[r.TagName], actual, "wrong computed fields for %s: %#v", r.TagName, r)
|
|
|
|
}
|
|
|
|
}
|