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.

parse_gogit_test.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. //go:build gogit
  4. package git
  5. import (
  6. "testing"
  7. "github.com/go-git/go-git/v5/plumbing/filemode"
  8. "github.com/go-git/go-git/v5/plumbing/object"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestParseTreeEntries(t *testing.T) {
  12. testCases := []struct {
  13. Input string
  14. Expected []*TreeEntry
  15. }{
  16. {
  17. Input: "",
  18. Expected: []*TreeEntry{},
  19. },
  20. {
  21. Input: "100644 blob 61ab7345a1a3bbc590068ccae37b8515cfc5843c 1022\texample/file2.txt\n",
  22. Expected: []*TreeEntry{
  23. {
  24. ID: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
  25. gogitTreeEntry: &object.TreeEntry{
  26. Hash: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
  27. Name: "example/file2.txt",
  28. Mode: filemode.Regular,
  29. },
  30. size: 1022,
  31. sized: true,
  32. },
  33. },
  34. },
  35. {
  36. Input: "120000 blob 61ab7345a1a3bbc590068ccae37b8515cfc5843c 234131\t\"example/\\n.txt\"\n" +
  37. "040000 tree 1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8 -\texample\n",
  38. Expected: []*TreeEntry{
  39. {
  40. ID: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
  41. gogitTreeEntry: &object.TreeEntry{
  42. Hash: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
  43. Name: "example/\n.txt",
  44. Mode: filemode.Symlink,
  45. },
  46. size: 234131,
  47. sized: true,
  48. },
  49. {
  50. ID: MustIDFromString("1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8"),
  51. sized: true,
  52. gogitTreeEntry: &object.TreeEntry{
  53. Hash: MustIDFromString("1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8"),
  54. Name: "example",
  55. Mode: filemode.Dir,
  56. },
  57. },
  58. },
  59. },
  60. }
  61. for _, testCase := range testCases {
  62. entries, err := ParseTreeEntries([]byte(testCase.Input))
  63. assert.NoError(t, err)
  64. assert.EqualValues(t, testCase.Expected, entries)
  65. }
  66. }