1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-12-23 22:11:10 +02:00
Files
imgproxy/storage/swift/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 swift
import (
"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
swiftStorage testutil.LazyObj[*swiftStorageWrapper]
}
func (s *ReaderTestSuite) SetupSuite() {
s.ReaderSuite.SetupSuite()
s.TestContainer = "test-container"
s.TestObjectKey = "test-object.txt"
// Initialize Swift storage
s.swiftStorage, _ = NewLazySuiteStorage(s.Lazy())
// Swift test storage returns 200 for range requests
// We have to skip partial content checks
s.SkipPartialContentChecks = true
s.Storage, _ = testutil.NewLazySuiteObj(s,
func() (storage.Reader, error) {
return s.swiftStorage().Storage, nil
},
)
}
func (s *ReaderTestSuite) SetupTest() {
// Recreate Swift blob for each test
conn := s.swiftStorage().Connection()
f, err := conn.ObjectCreate(s.T().Context(), s.TestContainer, s.TestObjectKey, true, "", "application/octet-stream", nil)
s.Require().NoError(err)
n, err := f.Write(s.TestData)
s.Require().Len(s.TestData, n)
s.Require().NoError(err)
f.Close()
}
func TestReader(t *testing.T) {
suite.Run(t, new(ReaderTestSuite))
}