2022-08-02 13:35:48 +00:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-08-02 13:35:48 +00:00
|
|
|
|
|
|
|
package filebuffer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 19:41:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-08-02 13:35:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFileBackedBuffer(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
MaxMemorySize int
|
|
|
|
Data string
|
|
|
|
}{
|
|
|
|
{5, "test"},
|
|
|
|
{5, "testtest"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
buf, err := CreateFromReader(strings.NewReader(c.Data), c.MaxMemorySize)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2022-08-02 13:35:48 +00:00
|
|
|
|
|
|
|
assert.EqualValues(t, len(c.Data), buf.Size())
|
|
|
|
|
|
|
|
data, err := io.ReadAll(buf)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2022-08-02 13:35:48 +00:00
|
|
|
assert.Equal(t, c.Data, string(data))
|
|
|
|
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, buf.Close())
|
2022-08-02 13:35:48 +00:00
|
|
|
}
|
|
|
|
}
|