MCPcopy
hub / github.com/cli/cli / TestExtractTitle

Function TestExtractTitle

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

Source from the content-addressed store, hash-verified

320}
321
322func TestExtractTitle(t *testing.T) {
323 tmpfile, err := os.CreateTemp(t.TempDir(), "gh-cli")
324 if err != nil {
325 t.Fatal(err)
326 }
327 defer tmpfile.Close()
328
329 type args struct {
330 filePath string
331 }
332 tests := []struct {
333 name string
334 prepare string
335 args args
336 want string
337 }{
338 {
339 name: "Complete front-matter",
340 prepare: `---
341name: Bug Report
342title: 'bug: '
343about: This is how you report bugs
344---
345
346**Template contents**
347`,
348 args: args{
349 filePath: tmpfile.Name(),
350 },
351 want: "bug: ",
352 },
353 {
354 name: "Incomplete front-matter",
355 prepare: `---
356about: This is how you report bugs
357---
358`,
359 args: args{
360 filePath: tmpfile.Name(),
361 },
362 want: "",
363 },
364 {
365 name: "No front-matter",
366 prepare: `name: This is not yaml!`,
367 args: args{
368 filePath: tmpfile.Name(),
369 },
370 want: "",
371 },
372 }
373 for _, tt := range tests {
374 t.Run(tt.name, func(t *testing.T) {
375 _ = os.WriteFile(tmpfile.Name(), []byte(tt.prepare), 0600)
376 if got := ExtractTitle(tt.args.filePath); got != tt.want {
377 t.Errorf("ExtractTitle() = %v, want %v", got, tt.want)
378 }
379 })

Callers

nothing calls this directly

Calls 5

ExtractTitleFunction · 0.85
CloseMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected