Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"testing"
|
|
|
|
issues_model "code.gitcaddy.com/server/v3/models/issues"
|
|
"code.gitcaddy.com/server/v3/models/unittest"
|
|
user_model "code.gitcaddy.com/server/v3/models/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIssue_AddLabels(t *testing.T) {
|
|
tests := []struct {
|
|
issueID int64
|
|
labelIDs []int64
|
|
doerID int64
|
|
}{
|
|
{1, []int64{1, 2}, 2}, // non-pull-request
|
|
{1, []int64{}, 2}, // non-pull-request, empty
|
|
{2, []int64{1, 2}, 2}, // pull-request
|
|
{2, []int64{}, 1}, // pull-request, empty
|
|
}
|
|
for _, test := range tests {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID})
|
|
labels := make([]*issues_model.Label, len(test.labelIDs))
|
|
for i, labelID := range test.labelIDs {
|
|
labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID})
|
|
}
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
|
|
assert.NoError(t, AddLabels(t.Context(), issue, doer, labels))
|
|
for _, labelID := range test.labelIDs {
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: labelID})
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIssue_AddLabel(t *testing.T) {
|
|
tests := []struct {
|
|
issueID int64
|
|
labelID int64
|
|
doerID int64
|
|
}{
|
|
{1, 2, 2}, // non-pull-request, not-already-added label
|
|
{1, 1, 2}, // non-pull-request, already-added label
|
|
{2, 2, 2}, // pull-request, not-already-added label
|
|
{2, 1, 2}, // pull-request, already-added label
|
|
}
|
|
for _, test := range tests {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID})
|
|
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: test.labelID})
|
|
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
|
|
assert.NoError(t, AddLabel(t.Context(), issue, doer, label))
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
|
|
}
|
|
}
|