test: add missing --type flag tests for issue list

Add flag parsing and behavior tests for gh issue list --type:
- TestNewCmdList/type_flag: verifies opts.IssueType is set
- Test_issueList/with_issue_type: verifies search path is forced
  and query includes type:Bug qualifier

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Kynan Ware 2026-03-29 17:27:12 -06:00
parent c00bc6a9b4
commit 3f1df513c5

View file

@ -25,6 +25,54 @@ import (
"github.com/stretchr/testify/require"
)
func TestNewCmdList(t *testing.T) {
tests := []struct {
name string
cli string
wantsErr bool
wants ListOptions
}{
{
name: "type flag",
cli: "--type Bug",
wants: ListOptions{
IssueType: "Bug",
State: "open",
LimitResults: 30,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &cmdutil.Factory{}
var gotOpts *ListOptions
cmd := NewCmdList(f, func(opts *ListOptions) error {
gotOpts = opts
return nil
})
argv, err := shlex.Split(tt.cli)
require.NoError(t, err)
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantsErr {
require.Error(t, err)
return
}
require.NoError(t, err)
require.NotNil(t, gotOpts)
assert.Equal(t, tt.wants.IssueType, gotOpts.IssueType)
assert.Equal(t, tt.wants.State, gotOpts.State)
assert.Equal(t, tt.wants.LimitResults, gotOpts.LimitResults)
})
}
}
func runCommand(rt http.RoundTripper, isTTY bool, cli string) (*test.CmdOut, error) {
ios, _, stdout, stderr := iostreams.Test()
ios.SetStdoutTTY(isTTY)
@ -484,6 +532,41 @@ func Test_issueList(t *testing.T) {
}))
},
},
{
name: "with issue type",
args: args{
// TODO advancedIssueSearchCleanup
// No need for feature detection once GHES 3.17 support ends.
detector: fd.AdvancedIssueSearchSupportedAsOptIn(),
limit: 30,
repo: ghrepo.New("OWNER", "REPO"),
filters: prShared.FilterOptions{
Entity: "issue",
State: "open",
IssueType: "Bug",
},
},
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.GraphQL(`query IssueSearch\b`),
httpmock.GraphQLQuery(`
{ "data": {
"repository": { "hasIssuesEnabled": true },
"search": {
"issueCount": 0,
"nodes": []
}
} }`, func(_ string, params map[string]interface{}) {
assert.Equal(t, map[string]interface{}{
"owner": "OWNER",
"repo": "REPO",
"limit": float64(30),
"query": "( type:Bug ) repo:OWNER/REPO state:open type:issue",
"type": "ISSUE_ADVANCED",
}, params)
}))
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {