mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-26 11:38:01 +02:00
Fix failed assertions reporting in testutil.TestDataProvider
This commit is contained in:
@@ -35,7 +35,7 @@ type LoadTestSuite struct {
|
||||
|
||||
// SetupSuite starts imgproxy instance server
|
||||
func (s *LoadTestSuite) SetupSuite() {
|
||||
s.testData = testutil.NewTestDataProvider(s.T())
|
||||
s.testData = testutil.NewTestDataProvider(s.T)
|
||||
s.testImagesPath = s.testData.Path("test-images")
|
||||
|
||||
c, err := imgproxy.LoadConfigFromEnv(nil)
|
||||
|
@@ -43,7 +43,7 @@ func (s *ProcessingHandlerTestSuite) SetupSuite() {
|
||||
logrus.SetOutput(io.Discard)
|
||||
|
||||
// Initialize test data provider (local test files)
|
||||
s.testData = testutil.NewTestDataProvider(s.T())
|
||||
s.testData = testutil.NewTestDataProvider(s.T)
|
||||
|
||||
s.config, _ = testutil.NewLazySuiteObj(s, func() (*imgproxy.Config, error) {
|
||||
c, err := imgproxy.LoadConfigFromEnv(nil)
|
||||
|
@@ -15,22 +15,25 @@ const (
|
||||
TestDataFolderName = "testdata"
|
||||
)
|
||||
|
||||
// TestDataProviderT is a function that returns a [testing.T]
|
||||
type TestDataProviderT func() *testing.T
|
||||
|
||||
// TestDataProvider provides access to test data images
|
||||
type TestDataProvider struct {
|
||||
path string
|
||||
t *testing.T
|
||||
t TestDataProviderT
|
||||
}
|
||||
|
||||
// New creates a new TestDataProvider
|
||||
func NewTestDataProvider(t *testing.T) *TestDataProvider {
|
||||
func NewTestDataProvider(t TestDataProviderT) *TestDataProvider {
|
||||
// if h, ok := t.(interface{ Helper() }); ok {
|
||||
// h.Helper()
|
||||
// }
|
||||
t.Helper()
|
||||
t().Helper()
|
||||
|
||||
path, err := findProjectRoot()
|
||||
if err != nil {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t(), err)
|
||||
}
|
||||
|
||||
return &TestDataProvider{
|
||||
@@ -80,10 +83,10 @@ func (p *TestDataProvider) Path(parts ...string) string {
|
||||
|
||||
// Read reads a test data file and returns it as bytes
|
||||
func (p *TestDataProvider) Read(name string) []byte {
|
||||
p.t.Helper()
|
||||
p.t().Helper()
|
||||
|
||||
data, err := os.ReadFile(p.Path(name))
|
||||
require.NoError(p.t, err)
|
||||
require.NoError(p.t(), err)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -95,5 +98,5 @@ func (p *TestDataProvider) Reader(name string) *bytes.Reader {
|
||||
// FileEqualsToReader compares the contents of a test data file with the contents of the given reader
|
||||
func (p *TestDataProvider) FileEqualsToReader(name string, reader io.Reader) bool {
|
||||
expected := p.Reader(name)
|
||||
return ReadersEqual(p.t, expected, reader)
|
||||
return ReadersEqual(p.t(), expected, reader)
|
||||
}
|
||||
|
Reference in New Issue
Block a user