mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
87 lines
2.5 KiB
Go
87 lines
2.5 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package issue
|
|
|
|
import (
|
|
"testing"
|
|
|
|
issues_model "github.com/hanzoai/git/models/issues"
|
|
repo_model "github.com/hanzoai/git/models/repo"
|
|
"github.com/hanzoai/git/models/unittest"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetRefEndNamesAndURLs(t *testing.T) {
|
|
issues := []*issues_model.Issue{
|
|
{ID: 1, Ref: "refs/heads/branch1"},
|
|
{ID: 2, Ref: "refs/tags/tag1"},
|
|
{ID: 3, Ref: "c0ffee"},
|
|
}
|
|
repoLink := "/foo/bar"
|
|
|
|
endNames, urls := GetRefEndNamesAndURLs(issues, repoLink)
|
|
assert.Equal(t, map[int64]string{1: "branch1", 2: "tag1", 3: "c0ffee"}, endNames)
|
|
assert.Equal(t, map[int64]string{
|
|
1: repoLink + "/src/branch/branch1",
|
|
2: repoLink + "/src/tag/tag1",
|
|
3: repoLink + "/src/commit/c0ffee",
|
|
}, urls)
|
|
}
|
|
|
|
func TestIssue_DeleteIssue(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
issueIDs, err := issues_model.GetIssueIDsByRepoID(t.Context(), 1)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, issueIDs, 5)
|
|
|
|
issue := &issues_model.Issue{
|
|
RepoID: 1,
|
|
ID: issueIDs[2],
|
|
}
|
|
|
|
_, err = deleteIssue(t.Context(), issue)
|
|
assert.NoError(t, err)
|
|
issueIDs, err = issues_model.GetIssueIDsByRepoID(t.Context(), 1)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, issueIDs, 4)
|
|
|
|
// check attachment removal
|
|
attachments, err := repo_model.GetAttachmentsByIssueID(t.Context(), 4)
|
|
assert.NoError(t, err)
|
|
issue, err = issues_model.GetIssueByID(t.Context(), 4)
|
|
assert.NoError(t, err)
|
|
_, err = deleteIssue(t.Context(), issue)
|
|
assert.NoError(t, err)
|
|
assert.Len(t, attachments, 2)
|
|
for i := range attachments {
|
|
attachment, err := repo_model.GetAttachmentByUUID(t.Context(), attachments[i].UUID)
|
|
assert.Error(t, err)
|
|
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
|
|
assert.Nil(t, attachment)
|
|
}
|
|
|
|
// check issue dependencies
|
|
user, err := user_model.GetUserByID(t.Context(), 1)
|
|
assert.NoError(t, err)
|
|
issue1, err := issues_model.GetIssueByID(t.Context(), 1)
|
|
assert.NoError(t, err)
|
|
issue2, err := issues_model.GetIssueByID(t.Context(), 2)
|
|
assert.NoError(t, err)
|
|
err = issues_model.CreateIssueDependency(t.Context(), user, issue1, issue2)
|
|
assert.NoError(t, err)
|
|
left, err := issues_model.IssueNoDependenciesLeft(t.Context(), issue1)
|
|
assert.NoError(t, err)
|
|
assert.False(t, left)
|
|
|
|
_, err = deleteIssue(t.Context(), issue2)
|
|
assert.NoError(t, err)
|
|
left, err = issues_model.IssueNoDependenciesLeft(t.Context(), issue1)
|
|
assert.NoError(t, err)
|
|
assert.True(t, left)
|
|
}
|