forgejo-sdk/gitea/repo_topics_test.go
6543 688ee1978e All Function return http responce (#416)
Add Docs on how to deal with this breaking change

doResponse should return responce in all cases, to prosses things manualy if wanted

helper func return http response

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/416
Reviewed-by: Andrew Thornton <art27@cantab.net>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
2020-09-14 02:37:09 +00:00

55 lines
1.6 KiB
Go

// 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.
package gitea
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
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "best")
assert.NoError(t, err)
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "git")
assert.NoError(t, err)
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "gitea")
assert.NoError(t, err)
_, err = c.AddRepoTopic(repo.Owner.UserName, repo.Name, "drone")
assert.NoError(t, err)
// Get List
tl, _, err := c.ListRepoTopics(repo.Owner.UserName, repo.Name, ListRepoTopicsOptions{})
assert.NoError(t, err)
assert.Len(t, tl, 4)
// Del
_, err = c.DeleteRepoTopic(repo.Owner.UserName, repo.Name, "drone")
assert.NoError(t, err)
_, err = c.DeleteRepoTopic(repo.Owner.UserName, repo.Name, "best")
assert.NoError(t, err)
tl, _, err = c.ListRepoTopics(repo.Owner.UserName, repo.Name, ListRepoTopicsOptions{})
assert.NoError(t, err)
assert.Len(t, tl, 2)
// Set List
newTopics := []string{"analog", "digital", "cat"}
_, err = c.SetRepoTopics(repo.Owner.UserName, repo.Name, newTopics)
assert.NoError(t, err)
tl, _, _ = c.ListRepoTopics(repo.Owner.UserName, repo.Name, ListRepoTopicsOptions{})
assert.Len(t, tl, 3)
sort.Strings(tl)
sort.Strings(newTopics)
assert.EqualValues(t, newTopics, tl)
}