2022-08-02 15:35:48 +02:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-27 19:20:29 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-08-02 15:35:48 +02:00
|
|
|
|
|
|
|
package filebuffer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 21:41:10 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-08-02 15:35:48 +02: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 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2022-08-02 15:35:48 +02:00
|
|
|
|
|
|
|
assert.EqualValues(t, len(c.Data), buf.Size())
|
|
|
|
|
|
|
|
data, err := io.ReadAll(buf)
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, err)
|
2022-08-02 15:35:48 +02:00
|
|
|
assert.Equal(t, c.Data, string(data))
|
|
|
|
|
2024-07-30 21:41:10 +02:00
|
|
|
require.NoError(t, buf.Close())
|
2022-08-02 15:35:48 +02:00
|
|
|
}
|
|
|
|
}
|