1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/storage/fs/reader_test.go
Victor Sokolov d5370d8077 Adds range checks to storage tests (#1566)
* Adds range checks to storage test

* Storage tests unified
2025-11-04 17:05:12 +01:00

50 lines
1.1 KiB
Go

package fs
import (
"os"
"path/filepath"
"testing"
"github.com/imgproxy/imgproxy/v3/storage"
"github.com/imgproxy/imgproxy/v3/storage/testsuite"
"github.com/imgproxy/imgproxy/v3/testutil"
"github.com/stretchr/testify/suite"
)
type ReaderTestSuite struct {
testsuite.ReaderSuite
fsStorage testutil.LazyObj[*Storage]
tmpDir testutil.LazyObj[string]
}
func (s *ReaderTestSuite) SetupSuite() {
s.ReaderSuite.SetupSuite()
s.TestObjectKey = "test-object.txt"
s.tmpDir, _ = testutil.NewLazySuiteObj(s,
func() (string, error) {
return s.T().TempDir(), nil
})
s.fsStorage, _ = NewLazySuiteStorage(s.Lazy(), s.tmpDir())
s.Storage, _ = testutil.NewLazySuiteObj(s,
func() (storage.Reader, error) {
return s.fsStorage(), nil
},
)
}
func (s *ReaderTestSuite) SetupTest() {
// Prepare FS storage - write test file directly
testFile := filepath.Join(s.tmpDir(), s.TestObjectKey)
err := os.MkdirAll(filepath.Dir(testFile), 0755)
s.Require().NoError(err)
err = os.WriteFile(testFile, s.TestData, 0644)
s.Require().NoError(err)
}
func TestReader(t *testing.T) {
suite.Run(t, new(ReaderTestSuite))
}