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_test.go 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2018 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 git
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "gopkg.in/src-d/go-git.v4/plumbing/filemode"
  9. "gopkg.in/src-d/go-git.v4/plumbing/object"
  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\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. },
  31. },
  32. },
  33. {
  34. Input: "120000 blob 61ab7345a1a3bbc590068ccae37b8515cfc5843c\t\"example/\\n.txt\"\n" +
  35. "040000 tree 1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8\texample\n",
  36. Expected: []*TreeEntry{
  37. {
  38. ID: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
  39. gogitTreeEntry: &object.TreeEntry{
  40. Hash: MustIDFromString("61ab7345a1a3bbc590068ccae37b8515cfc5843c"),
  41. Name: "example/\n.txt",
  42. Mode: filemode.Symlink,
  43. },
  44. },
  45. {
  46. ID: MustIDFromString("1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8"),
  47. gogitTreeEntry: &object.TreeEntry{
  48. Hash: MustIDFromString("1d01fb729fb0db5881daaa6030f9f2d3cd3d5ae8"),
  49. Name: "example",
  50. Mode: filemode.Dir,
  51. },
  52. },
  53. },
  54. },
  55. }
  56. for _, testCase := range testCases {
  57. entries, err := ParseTreeEntries([]byte(testCase.Input))
  58. assert.NoError(t, err)
  59. assert.EqualValues(t, testCase.Expected, entries)
  60. }
  61. }