MCPcopy Index your code
hub / github.com/cli/cli / TestExtractContents

Function TestExtractContents

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

Source from the content-addressed store, hash-verified

381}
382
383func TestExtractContents(t *testing.T) {
384 tmpfile, err := os.CreateTemp(t.TempDir(), "gh-cli")
385 if err != nil {
386 t.Fatal(err)
387 }
388 defer tmpfile.Close()
389
390 type args struct {
391 filePath string
392 }
393 tests := []struct {
394 name string
395 prepare string
396 args args
397 want string
398 }{
399 {
400 name: "Has front-matter",
401 prepare: `---
402name: Bug Report
403---
404
405
406Template contents
407---
408More of template
409`,
410 args: args{
411 filePath: tmpfile.Name(),
412 },
413 want: `Template contents
414---
415More of template
416`,
417 },
418 {
419 name: "No front-matter",
420 prepare: `Template contents
421---
422More of template
423---
424Even more
425`,
426 args: args{
427 filePath: tmpfile.Name(),
428 },
429 want: `Template contents
430---
431More of template
432---
433Even more
434`,
435 },
436 }
437 for _, tt := range tests {
438 t.Run(tt.name, func(t *testing.T) {
439 _ = os.WriteFile(tmpfile.Name(), []byte(tt.prepare), 0600)
440 if got := ExtractContents(tt.args.filePath); string(got) != tt.want {

Callers

nothing calls this directly

Calls 5

ExtractContentsFunction · 0.85
CloseMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected