MCPcopy
hub / github.com/cli/cli / TestTemplateManagerSelect

Function TestTemplateManagerSelect

pkg/cmd/pr/shared/templates_test.go:119–225  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestTemplateManagerSelect(t *testing.T) {
120 tests := []struct {
121 name string
122 isPR bool
123 templateName string
124 wantTemplate Template
125 wantErr bool
126 errMsg string
127 httpStubs func(*httpmock.Registry)
128 }{
129 {
130 name: "no templates found",
131 templateName: "Bug report",
132 httpStubs: func(reg *httpmock.Registry) {
133 reg.Register(
134 httpmock.GraphQL(`query IssueTemplates\b`),
135 httpmock.StringResponse(`{"data":{"repository":{"issueTemplates":[]}}}`),
136 )
137 },
138 wantErr: true,
139 errMsg: "no templates found",
140 },
141 {
142 name: "no matching templates found",
143 templateName: "Unknown report",
144 httpStubs: func(reg *httpmock.Registry) {
145 reg.Register(
146 httpmock.GraphQL(`query IssueTemplates\b`),
147 httpmock.StringResponse(`
148 { "data": { "repository": { "issueTemplates": [
149 { "name": "Bug report", "body": "I found a problem" },
150 { "name": "Feature request", "body": "I need a feature" }
151 ] } } }`),
152 )
153 },
154 wantErr: true,
155 errMsg: `template "Unknown report" not found`,
156 },
157 {
158 name: "matching issue template found",
159 templateName: "Bug report",
160 httpStubs: func(reg *httpmock.Registry) {
161 reg.Register(
162 httpmock.GraphQL(`query IssueTemplates\b`),
163 httpmock.StringResponse(`
164 { "data": { "repository": { "issueTemplates": [
165 { "name": "Bug report", "body": "I found a problem" },
166 { "name": "Feature request", "body": "I need a feature" }
167 ] } } }`),
168 )
169 },
170 wantTemplate: &issueTemplate{
171 Gname: "Bug report",
172 Gbody: "I found a problem",
173 },
174 },
175 {
176 name: "matching pull request template found",

Callers

nothing calls this directly

Calls 10

RegisterMethod · 0.95
VerifyMethod · 0.95
SelectMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
NewWithHostFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
NameMethod · 0.65
BodyMethod · 0.65

Tested by

no test coverage detected