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]>
84 lines
2.7 KiB
Go
84 lines
2.7 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/models/db"
|
|
repo_model "github.com/hanzoai/git/models/repo"
|
|
"github.com/hanzoai/git/models/unittest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAddTopic(t *testing.T) {
|
|
totalNrOfTopics := 6
|
|
repo1NrOfTopics := 3
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
topics, err := db.Find[repo_model.Topic](t.Context(), &repo_model.FindTopicOptions{})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, topics, totalNrOfTopics)
|
|
|
|
topics, total, err := db.FindAndCount[repo_model.Topic](t.Context(), &repo_model.FindTopicOptions{
|
|
ListOptions: db.ListOptions{Page: 1, PageSize: 2},
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, topics, 2)
|
|
assert.EqualValues(t, 6, total)
|
|
|
|
topics, err = db.Find[repo_model.Topic](t.Context(), &repo_model.FindTopicOptions{
|
|
RepoID: 1,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, topics, repo1NrOfTopics)
|
|
|
|
assert.NoError(t, repo_model.SaveTopics(t.Context(), 2, "golang"))
|
|
repo2NrOfTopics := 1
|
|
topics, err = db.Find[repo_model.Topic](t.Context(), &repo_model.FindTopicOptions{})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, topics, totalNrOfTopics)
|
|
|
|
topics, err = db.Find[repo_model.Topic](t.Context(), &repo_model.FindTopicOptions{
|
|
RepoID: 2,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, topics, repo2NrOfTopics)
|
|
|
|
assert.NoError(t, repo_model.SaveTopics(t.Context(), 2, "golang", "gitea"))
|
|
repo2NrOfTopics = 2
|
|
totalNrOfTopics++
|
|
topic, err := repo_model.GetTopicByName(t.Context(), "gitea")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, 1, topic.RepoCount)
|
|
|
|
topics, err = db.Find[repo_model.Topic](t.Context(), &repo_model.FindTopicOptions{})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, topics, totalNrOfTopics)
|
|
|
|
topics, err = db.Find[repo_model.Topic](t.Context(), &repo_model.FindTopicOptions{
|
|
RepoID: 2,
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, topics, repo2NrOfTopics)
|
|
}
|
|
|
|
func TestTopicValidator(t *testing.T) {
|
|
assert.True(t, repo_model.ValidateTopic("12345"))
|
|
assert.True(t, repo_model.ValidateTopic("2-test"))
|
|
assert.True(t, repo_model.ValidateTopic("foo.bar"))
|
|
assert.True(t, repo_model.ValidateTopic("test-3"))
|
|
assert.True(t, repo_model.ValidateTopic("first"))
|
|
assert.True(t, repo_model.ValidateTopic("second-test-topic"))
|
|
assert.True(t, repo_model.ValidateTopic("third-project-topic-with-max-length"))
|
|
|
|
assert.False(t, repo_model.ValidateTopic("$fourth-test,topic"))
|
|
assert.False(t, repo_model.ValidateTopic("-fifth-test-topic"))
|
|
assert.False(t, repo_model.ValidateTopic("sixth-go-project-topic-with-excess-length"))
|
|
assert.False(t, repo_model.ValidateTopic(".foo"))
|
|
}
|