1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/storage/s3/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

52 lines
1.2 KiB
Go

package s3
import (
"bytes"
"net/http"
"testing"
"time"
"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
s3Storage testutil.LazyObj[*s3StorageWrapper]
}
func (s *ReaderTestSuite) SetupSuite() {
s.ReaderSuite.SetupSuite()
s.TestContainer = "test-container"
s.TestObjectKey = "test-object.txt"
// Initialize S3 storage
s.s3Storage, _ = NewLazySuiteStorage(s.Lazy())
s.Storage, _ = testutil.NewLazySuiteObj(s,
func() (storage.Reader, error) {
return s.s3Storage().Storage, nil
},
)
}
func (s *ReaderTestSuite) SetupTest() {
// Recreate S3 blob for each test using backend directly
backend := s.s3Storage().Server().Backend()
metadata := map[string]string{
"Content-Type": "application/octet-stream",
"Last-Modified": time.Now().Format(http.TimeFormat),
}
_, err := backend.PutObject(s.TestContainer, s.TestObjectKey, metadata,
bytes.NewReader(s.TestData), int64(len(s.TestData)), nil)
s.Require().NoError(err)
}
func TestReader(t *testing.T) {
suite.Run(t, new(ReaderTestSuite))
}