forgejo/services/issue/label_test.go
TheFox0x7 ce563ade3d
Some checks are pending
/ release (push) Waiting to run
testing / test-remote-cacher (map[image:registry.redict.io/redict:7.3.0-scratch port:6379]) (push) Blocked by required conditions
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-remote-cacher (map[image:ghcr.io/microsoft/garnet-alpine:1.0.14 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:redis:7.2 port:6379]) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
enable linter testifylint on v8 (#4573)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4573
Co-authored-by: TheFox0x7 <thefox0x7@gmail.com>
Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
2024-07-30 19:41:27 +00:00

62 lines
2.1 KiB
Go

// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package issue
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/require"
)
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 {
require.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})
require.NoError(t, AddLabels(db.DefaultContext, 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 {
require.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})
require.NoError(t, AddLabel(db.DefaultContext, issue, doer, label))
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
}
}