MCPcopy
hub / github.com/cli/cli / TestTemplateManager_hasAPI

Function TestTemplateManager_hasAPI

pkg/cmd/pr/shared/templates_test.go:16–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestTemplateManager_hasAPI(t *testing.T) {
17 rootDir := t.TempDir()
18 legacyTemplateFile := filepath.Join(rootDir, ".github", "ISSUE_TEMPLATE.md")
19 _ = os.MkdirAll(filepath.Dir(legacyTemplateFile), 0755)
20 _ = os.WriteFile(legacyTemplateFile, []byte("LEGACY"), 0644)
21
22 tr := httpmock.Registry{}
23 httpClient := &http.Client{Transport: &tr}
24 defer tr.Verify(t)
25
26 tr.Register(
27 httpmock.GraphQL(`query IssueTemplates\b`),
28 httpmock.StringResponse(`{"data":{"repository":{
29 "issueTemplates": [
30 {"name": "Bug report", "body": "I found a problem", "title": "bug: "},
31 {"name": "Feature request", "body": "I need a feature", "title": "request: "}
32 ]
33 }}}`))
34
35 pm := &prompter.PrompterMock{}
36 pm.SelectFunc = func(p, _ string, opts []string) (int, error) {
37 if p == "Choose a template" {
38 return prompter.IndexFor(opts, "Feature request")
39 } else {
40 return -1, prompter.NoSuchPromptErr(p)
41 }
42 }
43
44 m := templateManager{
45 repo: ghrepo.NewWithHost("OWNER", "REPO", "example.com"),
46 rootDir: rootDir,
47 allowFS: true,
48 isPR: false,
49 httpClient: httpClient,
50 detector: &fd.EnabledDetectorMock{},
51 prompter: pm,
52 }
53
54 hasTemplates, err := m.HasTemplates()
55 assert.NoError(t, err)
56 assert.True(t, hasTemplates)
57
58 assert.Equal(t, "LEGACY", string(m.LegacyBody()))
59
60 tpl, err := m.Choose()
61
62 assert.NoError(t, err)
63 assert.Equal(t, "Feature request", tpl.NameForSubmit())
64 assert.Equal(t, "I need a feature", string(tpl.Body()))
65 assert.Equal(t, "request: ", tpl.Title())
66}
67
68func TestTemplateManager_hasAPI_PullRequest(t *testing.T) {
69 rootDir := t.TempDir()

Callers

nothing calls this directly

Calls 15

VerifyMethod · 0.95
RegisterMethod · 0.95
HasTemplatesMethod · 0.95
LegacyBodyMethod · 0.95
ChooseMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
IndexForFunction · 0.92
NoSuchPromptErrFunction · 0.92
NewWithHostFunction · 0.92
JoinMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected