gitea.tea/cmd/teams/list_test.go
Ross Golder 6c8cef6046
test(teams): cover metadata, flags, and helper behaviour
Verify command names, aliases, usage, and the expected flag set on
each new subcommand. Exercise ParseRepoUnits for default, single,
multiple, case-insensitive, and unknown inputs.
2026-09-05 09:54:10 +07:00

81 lines
1.9 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package teams
import (
"testing"
gitea "gitea.dev/sdk"
"github.com/stretchr/testify/assert"
)
func TestListCommandMetadata(t *testing.T) {
cmd := &CmdTeamsList
assert.Equal(t, "list", cmd.Name)
assert.Contains(t, cmd.Aliases, "ls")
assert.Equal(t, "List teams in an organization", cmd.Usage)
assert.Equal(t, "List all teams in the specified organization", cmd.Description)
assert.NotNil(t, cmd.Action)
}
func TestListCommandFlags(t *testing.T) {
cmd := &CmdTeamsList
have := make(map[string]bool, len(cmd.Flags))
for _, flag := range cmd.Flags {
have[flag.Names()[0]] = true
}
for _, name := range []string{"page", "limit", "search", "login", "output"} {
assert.True(t, have[name], "expected flag %q not found", name)
}
}
func TestParseRepoUnits(t *testing.T) {
tests := []struct {
name string
input []string
expected []gitea.RepoUnitType
}{
{
name: "empty input yields default units",
input: nil,
expected: []gitea.RepoUnitType{gitea.RepoUnitCode, gitea.RepoUnitIssues, gitea.RepoUnitPulls, gitea.RepoUnitReleases},
},
{
name: "single code unit",
input: []string{"code"},
expected: []gitea.RepoUnitType{gitea.RepoUnitCode},
},
{
name: "multiple units",
input: []string{"code", "issues", "wiki"},
expected: []gitea.RepoUnitType{
gitea.RepoUnitCode,
gitea.RepoUnitIssues,
gitea.RepoUnitWiki,
},
},
{
name: "case-insensitive",
input: []string{"CODE", "IsSuEs"},
expected: []gitea.RepoUnitType{
gitea.RepoUnitCode,
gitea.RepoUnitIssues,
},
},
{
name: "unknown unit is silently dropped",
input: []string{"code", "bogus"},
expected: []gitea.RepoUnitType{gitea.RepoUnitCode},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, ParseRepoUnits(tt.input))
})
}
}