forked from forgejo/forgejo
[TESTS] issue & PR templates in .forgejo
are recognized
This adds a few tests for the previous change, to verify that issue template configs, issue templates and pr templates are all recognized in `.forgejo` directories. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
parent
271db6ff22
commit
1624ebc836
3 changed files with 201 additions and 23 deletions
|
@ -34,13 +34,24 @@ func TestAPIIssueTemplateList(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("existing template", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer func() {
|
||||
deleteFileInBranch(user, repo, "ISSUE_TEMPLATE/test.md", repo.DefaultBranch)
|
||||
}()
|
||||
templateCandidates := []string{
|
||||
".forgejo/ISSUE_TEMPLATE/test.md",
|
||||
".forgejo/issue_template/test.md",
|
||||
".gitea/ISSUE_TEMPLATE/test.md",
|
||||
".gitea/issue_template/test.md",
|
||||
".github/ISSUE_TEMPLATE/test.md",
|
||||
".github/issue_template/test.md",
|
||||
}
|
||||
|
||||
err := createOrReplaceFileInBranch(user, repo, "ISSUE_TEMPLATE/test.md", repo.DefaultBranch,
|
||||
`---
|
||||
for _, template := range templateCandidates {
|
||||
t.Run(template, func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer func() {
|
||||
deleteFileInBranch(user, repo, template, repo.DefaultBranch)
|
||||
}()
|
||||
|
||||
err := createOrReplaceFileInBranch(user, repo, template, repo.DefaultBranch,
|
||||
`---
|
||||
name: 'Template Name'
|
||||
about: 'This template is for testing!'
|
||||
title: '[TEST] '
|
||||
|
@ -48,17 +59,56 @@ ref: 'main'
|
|||
---
|
||||
|
||||
This is the template!`)
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/issue_templates", repo.FullName()))
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var issueTemplates []*api.IssueTemplate
|
||||
DecodeJSON(t, resp, &issueTemplates)
|
||||
assert.Len(t, issueTemplates, 1)
|
||||
assert.Equal(t, "Template Name", issueTemplates[0].Name)
|
||||
assert.Equal(t, "This template is for testing!", issueTemplates[0].About)
|
||||
assert.Equal(t, "refs/heads/main", issueTemplates[0].Ref)
|
||||
assert.Equal(t, template, issueTemplates[0].FileName)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("multiple templates", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
templatePriority := []string{
|
||||
".forgejo/issue_template/test.md",
|
||||
".gitea/issue_template/test.md",
|
||||
".github/issue_template/test.md",
|
||||
}
|
||||
defer func() {
|
||||
for _, template := range templatePriority {
|
||||
deleteFileInBranch(user, repo, template, repo.DefaultBranch)
|
||||
}
|
||||
}()
|
||||
|
||||
for _, template := range templatePriority {
|
||||
err := createOrReplaceFileInBranch(user, repo, template, repo.DefaultBranch,
|
||||
`---
|
||||
name: 'Template Name'
|
||||
about: 'This template is for testing!'
|
||||
title: '[TEST] '
|
||||
ref: 'main'
|
||||
---
|
||||
|
||||
This is the template!`)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/issue_templates", repo.FullName()))
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var issueTemplates []*api.IssueTemplate
|
||||
DecodeJSON(t, resp, &issueTemplates)
|
||||
assert.Len(t, issueTemplates, 1)
|
||||
assert.Equal(t, "Template Name", issueTemplates[0].Name)
|
||||
assert.Equal(t, "This template is for testing!", issueTemplates[0].About)
|
||||
assert.Equal(t, "refs/heads/main", issueTemplates[0].Ref)
|
||||
assert.Equal(t, "ISSUE_TEMPLATE/test.md", issueTemplates[0].FileName)
|
||||
|
||||
// If templates have the same filename and content, but in different
|
||||
// directories, they count as different templates, and all are
|
||||
// considered.
|
||||
assert.Len(t, issueTemplates, 3)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue