You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api_gitignore_templates_test.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "fmt"
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/modules/options"
  9. repo_module "code.gitea.io/gitea/modules/repository"
  10. api "code.gitea.io/gitea/modules/structs"
  11. "code.gitea.io/gitea/tests"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestAPIListGitignoresTemplates(t *testing.T) {
  15. defer tests.PrepareTestEnv(t)()
  16. req := NewRequest(t, "GET", "/api/v1/gitignore/templates")
  17. resp := MakeRequest(t, req, http.StatusOK)
  18. // This tests if the API returns a list of strings
  19. var gitignoreList []string
  20. DecodeJSON(t, resp, &gitignoreList)
  21. }
  22. func TestAPIGetGitignoreTemplateInfo(t *testing.T) {
  23. defer tests.PrepareTestEnv(t)()
  24. // If Gitea has for some reason no Gitignore templates, we need to skip this test
  25. if len(repo_module.Gitignores) == 0 {
  26. return
  27. }
  28. // Use the first template for the test
  29. templateName := repo_module.Gitignores[0]
  30. urlStr := fmt.Sprintf("/api/v1/gitignore/templates/%s", templateName)
  31. req := NewRequest(t, "GET", urlStr)
  32. resp := MakeRequest(t, req, http.StatusOK)
  33. var templateInfo api.GitignoreTemplateInfo
  34. DecodeJSON(t, resp, &templateInfo)
  35. // We get the text of the template here
  36. text, _ := options.Gitignore(templateName)
  37. assert.Equal(t, templateInfo.Name, templateName)
  38. assert.Equal(t, templateInfo.Source, string(text))
  39. }