mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-26 09:14:32 +00:00
fix
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -100,3 +103,31 @@ func TestParseTreeEntriesInvalid(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, entries)
|
||||
}
|
||||
|
||||
func TestParseCatFileTreeLine(t *testing.T) {
|
||||
input := "100644 looooooooooooooooooooooooong-file-name.txt\x0012345678901234567890"
|
||||
input += "40755 some-directory\x00abcdefg123abcdefg123"
|
||||
|
||||
var readCount int
|
||||
|
||||
buf := bufio.NewReaderSize(strings.NewReader(input), 20) // NewReaderSize has a limit: min buffer size = 16
|
||||
mode, name, objID, n, err := ParseCatFileTreeLine(Sha1ObjectFormat, buf)
|
||||
readCount += n
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, EntryModeBlob, mode)
|
||||
assert.Equal(t, "looooooooooooooooooooooooong-file-name.txt", name)
|
||||
assert.Equal(t, "12345678901234567890", string(objID.RawValue()))
|
||||
|
||||
mode, name, objID, n, err = ParseCatFileTreeLine(Sha1ObjectFormat, buf)
|
||||
readCount += n
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, EntryModeTree, mode)
|
||||
assert.Equal(t, "some-directory", name)
|
||||
assert.Equal(t, "abcdefg123abcdefg123", string(objID.RawValue()))
|
||||
|
||||
assert.Equal(t, len(input), readCount)
|
||||
|
||||
_, _, _, n, err = ParseCatFileTreeLine(Sha1ObjectFormat, buf)
|
||||
assert.ErrorIs(t, err, io.EOF)
|
||||
assert.Zero(t, n)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user