github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/util/filebuffer/file_backed_buffer_test.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package filebuffer
     7  
     8  import (
     9  	"io"
    10  	"strings"
    11  	"testing"
    12  
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestFileBackedBuffer(t *testing.T) {
    17  	cases := []struct {
    18  		MaxMemorySize int
    19  		Data          string
    20  	}{
    21  		{5, "test"},
    22  		{5, "testtest"},
    23  	}
    24  
    25  	for _, c := range cases {
    26  		buf, err := CreateFromReader(strings.NewReader(c.Data), c.MaxMemorySize)
    27  		assert.NoError(t, err)
    28  
    29  		assert.EqualValues(t, len(c.Data), buf.Size())
    30  
    31  		data, err := io.ReadAll(buf)
    32  		assert.NoError(t, err)
    33  		assert.Equal(t, c.Data, string(data))
    34  
    35  		assert.NoError(t, buf.Close())
    36  	}
    37  }