You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.1 KiB
81 lines
2.1 KiB
7 years ago
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package repo
|
||
7 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
|
||
7 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestAddTopic(t *testing.T) {
|
||
5 years ago
|
totalNrOfTopics := 6
|
||
|
repo1NrOfTopics := 3
|
||
|
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
7 years ago
|
|
||
3 years ago
|
topics, _, err := FindTopics(&FindTopicOptions{})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, topics, totalNrOfTopics)
|
||
7 years ago
|
|
||
3 years ago
|
topics, total, err := FindTopics(&FindTopicOptions{
|
||
3 years ago
|
ListOptions: db.ListOptions{Page: 1, PageSize: 2},
|
||
7 years ago
|
})
|
||
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, topics, 2)
|
||
3 years ago
|
assert.EqualValues(t, 6, total)
|
||
7 years ago
|
|
||
3 years ago
|
topics, _, err = FindTopics(&FindTopicOptions{
|
||
7 years ago
|
RepoID: 1,
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, topics, repo1NrOfTopics)
|
||
7 years ago
|
|
||
|
assert.NoError(t, SaveTopics(2, "golang"))
|
||
3 years ago
|
repo2NrOfTopics := 1
|
||
3 years ago
|
topics, _, err = FindTopics(&FindTopicOptions{})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, topics, totalNrOfTopics)
|
||
7 years ago
|
|
||
3 years ago
|
topics, _, err = FindTopics(&FindTopicOptions{
|
||
7 years ago
|
RepoID: 2,
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, topics, repo2NrOfTopics)
|
||
7 years ago
|
|
||
|
assert.NoError(t, SaveTopics(2, "golang", "gitea"))
|
||
5 years ago
|
repo2NrOfTopics = 2
|
||
|
totalNrOfTopics++
|
||
7 years ago
|
topic, err := GetTopicByName("gitea")
|
||
|
assert.NoError(t, err)
|
||
|
assert.EqualValues(t, 1, topic.RepoCount)
|
||
|
|
||
3 years ago
|
topics, _, err = FindTopics(&FindTopicOptions{})
|
||
7 years ago
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, topics, totalNrOfTopics)
|
||
7 years ago
|
|
||
3 years ago
|
topics, _, err = FindTopics(&FindTopicOptions{
|
||
7 years ago
|
RepoID: 2,
|
||
|
})
|
||
|
assert.NoError(t, err)
|
||
4 years ago
|
assert.Len(t, topics, repo2NrOfTopics)
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
|
func TestTopicValidator(t *testing.T) {
|
||
|
assert.True(t, ValidateTopic("12345"))
|
||
|
assert.True(t, ValidateTopic("2-test"))
|
||
|
assert.True(t, ValidateTopic("test-3"))
|
||
|
assert.True(t, ValidateTopic("first"))
|
||
|
assert.True(t, ValidateTopic("second-test-topic"))
|
||
|
assert.True(t, ValidateTopic("third-project-topic-with-max-length"))
|
||
|
|
||
|
assert.False(t, ValidateTopic("$fourth-test,topic"))
|
||
|
assert.False(t, ValidateTopic("-fifth-test-topic"))
|
||
|
assert.False(t, ValidateTopic("sixth-go-project-topic-with-excess-length"))
|
||
|
}
|