468d48c978
- Add the API to search for teams on a organization by the `/orgs/{org}/teams/search` API of Gitea. - The response body of the API is a bit weird because it the JSON can return three fields "data", "error", "ok", first check if there's a general HTTP error. Otherwise when ok is set to false, return a error with the given error message of the error field. When ok is set to true, simply return the data. CC @fnetx Co-authored-by: Andrew Thornton <art27@cantab.net> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/577 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: Gusted <williamzijl7@hotmail.com> Co-committed-by: Gusted <williamzijl7@hotmail.com>
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
// Copyright 2021 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"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func createTestOrgTeams(t *testing.T, c *Client, org, name string, accessMode AccessMode, units []RepoUnitType) (*Team, error) {
|
|
team, _, e := c.CreateTeam(org, CreateTeamOption{
|
|
Name: name,
|
|
Description: name + "'s team desc",
|
|
Permission: accessMode,
|
|
CanCreateOrgRepo: false,
|
|
IncludesAllRepositories: false,
|
|
Units: units,
|
|
})
|
|
assert.NoError(t, e)
|
|
assert.NotNil(t, team)
|
|
return team, e
|
|
}
|
|
|
|
func TestTeamSearch(t *testing.T) {
|
|
log.Println("== TestTeamSearch ==")
|
|
c := newTestClient()
|
|
|
|
orgName := "TestTeamsOrg"
|
|
// prepare for test
|
|
_, _, err := c.CreateOrg(CreateOrgOption{
|
|
Name: orgName,
|
|
Visibility: VisibleTypePublic,
|
|
RepoAdminChangeTeamAccess: true,
|
|
})
|
|
defer func() {
|
|
_, _ = c.DeleteOrg(orgName)
|
|
}()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
if _, err = createTestOrgTeams(t, c, orgName, "Admins", AccessModeAdmin, []RepoUnitType{RepoUnitCode, RepoUnitIssues, RepoUnitPulls, RepoUnitReleases}); err != nil {
|
|
return
|
|
}
|
|
|
|
teams, _, err := c.SearchOrgTeams(orgName, &SearchTeamsOptions{
|
|
Query: "Admins",
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.Len(t, teams, 1)
|
|
|
|
assert.Equal(t, "Admins", teams[0].Name)
|
|
}
|