MCPcopy
hub / github.com/cli/cli / TestExtractName

Function TestExtractName

pkg/githubtemplate/github_template_test.go:262–320  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

260}
261
262func TestExtractName(t *testing.T) {
263 tmpfile, err := os.CreateTemp(t.TempDir(), "gh-cli")
264 if err != nil {
265 t.Fatal(err)
266 }
267 defer tmpfile.Close()
268
269 type args struct {
270 filePath string
271 }
272 tests := []struct {
273 name string
274 prepare string
275 args args
276 want string
277 }{
278 {
279 name: "Complete front-matter",
280 prepare: `---
281name: Bug Report
282about: This is how you report bugs
283---
284
285**Template contents**
286`,
287 args: args{
288 filePath: tmpfile.Name(),
289 },
290 want: "Bug Report",
291 },
292 {
293 name: "Incomplete front-matter",
294 prepare: `---
295about: This is how you report bugs
296---
297`,
298 args: args{
299 filePath: tmpfile.Name(),
300 },
301 want: path.Base(tmpfile.Name()),
302 },
303 {
304 name: "No front-matter",
305 prepare: `name: This is not yaml!`,
306 args: args{
307 filePath: tmpfile.Name(),
308 },
309 want: path.Base(tmpfile.Name()),
310 },
311 }
312 for _, tt := range tests {
313 t.Run(tt.name, func(t *testing.T) {
314 _ = os.WriteFile(tmpfile.Name(), []byte(tt.prepare), 0600)
315 if got := ExtractName(tt.args.filePath); got != tt.want {
316 t.Errorf("ExtractName() = %v, want %v", got, tt.want)
317 }
318 })
319 }

Callers

nothing calls this directly

Calls 6

ExtractNameFunction · 0.85
BaseMethod · 0.80
CloseMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected