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

Function TestPreviewRun_Interactive

pkg/cmd/skills/preview/preview_test.go:456–519  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

454}
455
456func TestPreviewRun_Interactive(t *testing.T) {
457 skillContent := "# Selected Skill\n\nContent here."
458 encodedContent := base64.StdEncoding.EncodeToString([]byte(skillContent))
459
460 reg := &httpmock.Registry{}
461 defer reg.Verify(t)
462 reg.Register(
463 httpmock.REST("GET", "repos/owner/repo/releases/latest"),
464 httpmock.StringResponse(`{"tag_name": "v1.0.0"}`),
465 )
466 reg.Register(
467 httpmock.REST("GET", "repos/owner/repo/git/ref/tags/v1.0.0"),
468 httpmock.StringResponse(`{"object": {"sha": "abc123", "type": "commit"}}`),
469 )
470 reg.Register(
471 httpmock.REST("GET", "repos/owner/repo/git/trees/abc123"),
472 httpmock.StringResponse(`{
473 "sha": "abc123",
474 "truncated": false,
475 "tree": [
476 {"path": "skills/alpha", "type": "tree", "sha": "tree-a"},
477 {"path": "skills/alpha/SKILL.md", "type": "blob", "sha": "blob-a"},
478 {"path": "skills/beta", "type": "tree", "sha": "tree-b"},
479 {"path": "skills/beta/SKILL.md", "type": "blob", "sha": "blob-b"}
480 ]
481 }`),
482 )
483 reg.Register(
484 httpmock.REST("GET", "repos/owner/repo/git/trees/tree-b"),
485 httpmock.StringResponse(`{
486 "tree": [
487 {"path": "SKILL.md", "type": "blob", "sha": "blob-b", "size": 40}
488 ]
489 }`),
490 )
491 reg.Register(
492 httpmock.REST("GET", "repos/owner/repo/git/blobs/blob-b"),
493 httpmock.StringResponse(`{"sha": "blob-b", "content": "`+encodedContent+`", "encoding": "base64"}`),
494 )
495
496 ios, _, stdout, _ := iostreams.Test()
497 ios.SetStdoutTTY(true)
498 ios.SetStdinTTY(true)
499
500 pm := &prompter.PrompterMock{
501 SelectFunc: func(prompt string, defaultValue string, options []string) (int, error) {
502 assert.Equal(t, "Select a skill to preview:", prompt)
503 assert.Equal(t, []string{"alpha", "beta"}, options)
504 return 1, nil // select "beta"
505 },
506 }
507
508 opts := &PreviewOptions{
509 IO: ios,
510 HttpClient: func() (*http.Client, error) { return &http.Client{Transport: reg}, nil },
511 Prompter: pm,
512 repo: ghrepo.New("owner", "repo"),
513 Telemetry: &telemetry.NoOpService{},

Callers

nothing calls this directly

Calls 12

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
TestFunction · 0.92
NewFunction · 0.92
previewRunFunction · 0.85
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
EqualMethod · 0.80
ContainsMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected