2024-05-03 16:43:42 +01:00
|
|
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
2024-02-23 00:26:49 +00:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-02-09 18:31:34 +00:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
2024-02-23 00:26:49 +00:00
|
|
|
package forgejo
|
2020-02-09 18:31:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepoTopics(t *testing.T) {
|
|
|
|
log.Println("== TestRepoTopics ==")
|
|
|
|
c := newTestClient()
|
|
|
|
repo, err := createTestRepo(t, "RandomTopic", c)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Add
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "best")
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "git")
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
2024-02-23 00:26:49 +00:00
|
|
|
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "forgejo")
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "drone")
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Get List
|
2020-09-14 03:37:09 +01:00
|
|
|
tl, _, err := c.ListRepoTopics(repo.Owner.UserName, repo.Name, ListRepoTopicsOptions{})
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, tl, 4)
|
|
|
|
|
|
|
|
// Del
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.DeleteRepoTopic(repo.Owner.UserName, repo.Name, "drone")
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.DeleteRepoTopic(repo.Owner.UserName, repo.Name, "best")
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
tl, _, err = c.ListRepoTopics(repo.Owner.UserName, repo.Name, ListRepoTopicsOptions{})
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, tl, 2)
|
|
|
|
|
|
|
|
// Set List
|
|
|
|
newTopics := []string{"analog", "digital", "cat"}
|
2020-09-14 03:37:09 +01:00
|
|
|
_, err = c.SetRepoTopics(repo.Owner.UserName, repo.Name, newTopics)
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.NoError(t, err)
|
2020-09-14 03:37:09 +01:00
|
|
|
tl, _, _ = c.ListRepoTopics(repo.Owner.UserName, repo.Name, ListRepoTopicsOptions{})
|
2020-02-09 18:31:34 +00:00
|
|
|
assert.Len(t, tl, 3)
|
|
|
|
|
|
|
|
sort.Strings(tl)
|
|
|
|
sort.Strings(newTopics)
|
|
|
|
assert.EqualValues(t, newTopics, tl)
|
|
|
|
}
|