本站源代码
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

52 lines
1.4KB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repofiles
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/models"
  8. api "code.gitea.io/gitea/modules/structs"
  9. "code.gitea.io/gitea/modules/test"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestGetTreeBySHA(t *testing.T) {
  13. models.PrepareTestEnv(t)
  14. ctx := test.MockContext(t, "user2/repo1")
  15. test.LoadRepo(t, ctx, 1)
  16. test.LoadRepoCommit(t, ctx)
  17. test.LoadUser(t, ctx, 2)
  18. test.LoadGitRepo(t, ctx)
  19. sha := ctx.Repo.Repository.DefaultBranch
  20. page := 1
  21. perPage := 10
  22. ctx.SetParams(":id", "1")
  23. ctx.SetParams(":sha", sha)
  24. tree, err := GetTreeBySHA(ctx.Repo.Repository, ctx.Params(":sha"), page, perPage, true)
  25. assert.Nil(t, err)
  26. expectedTree := &api.GitTreeResponse{
  27. SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
  28. URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/trees/65f1bf27bc3bf70f64657658635e66094edbcb4d",
  29. Entries: []api.GitEntry{
  30. {
  31. Path: "README.md",
  32. Mode: "100644",
  33. Type: "blob",
  34. Size: 30,
  35. SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f",
  36. URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/4b4851ad51df6a7d9f25c979345979eaeb5b349f",
  37. },
  38. },
  39. Truncated: false,
  40. Page: 1,
  41. TotalCount: 1,
  42. }
  43. assert.EqualValues(t, expectedTree, tree)
  44. }
上海开阖软件有限公司 沪ICP备12045867号-1