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.9KB

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