2024-02-23 00:26:49 +00:00
|
|
|
// Copyright 2024 The Forgjo Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-08-13 16:56:50 +01:00
|
|
|
// 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.
|
|
|
|
|
2024-02-23 00:26:49 +00:00
|
|
|
package forgejo
|
2021-08-13 16:56:50 +01:00
|
|
|
|
|
|
|
import (
|
2022-04-26 20:21:25 +01:00
|
|
|
"log"
|
2021-08-13 16:56:50 +01:00
|
|
|
"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
|
|
|
|
}
|
2022-04-26 20:21:25 +01:00
|
|
|
|
|
|
|
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)
|
2022-09-15 19:26:31 +01:00
|
|
|
if assert.Len(t, teams, 1) {
|
|
|
|
assert.Equal(t, "Admins", teams[0].Name)
|
|
|
|
}
|
2022-04-26 20:21:25 +01:00
|
|
|
}
|