(t *testing.T)
| 320 | } |
| 321 | |
| 322 | func 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: `--- |
| 341 | name: Bug Report |
| 342 | title: 'bug: ' |
| 343 | about: 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: `--- |
| 356 | about: 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 | }) |
nothing calls this directly
no test coverage detected