(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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 | |
| 68 | func TestTemplateManager_hasAPI_PullRequest(t *testing.T) { |
| 69 | rootDir := t.TempDir() |
nothing calls this directly
no test coverage detected