mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-21 23:37:31 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"testing"
|
|
"time"
|
|
|
|
"go.uber.org/mock/gomock"
|
|
|
|
"github.com/zitadel/zitadel/internal/static"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
func NewStorage(t *testing.T) *MockStorage {
|
|
return NewMockStorage(gomock.NewController(t))
|
|
}
|
|
|
|
func (m *MockStorage) ExpectPutObject() *MockStorage {
|
|
m.EXPECT().
|
|
PutObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
|
DoAndReturn(func(ctx context.Context, instanceID, location, resourceOwner, name, contentType string, objectType static.ObjectType, object io.Reader, objectSize int64) (*static.Asset, error) {
|
|
hash, _ := io.ReadAll(object)
|
|
return &static.Asset{
|
|
InstanceID: instanceID,
|
|
Name: name,
|
|
Hash: string(hash),
|
|
Size: objectSize,
|
|
LastModified: time.Now(),
|
|
Location: location,
|
|
ContentType: contentType,
|
|
}, nil
|
|
})
|
|
return m
|
|
}
|
|
|
|
func (m *MockStorage) ExpectPutObjectError() *MockStorage {
|
|
m.EXPECT().
|
|
PutObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
|
Return(nil, zerrors.ThrowInternal(nil, "", ""))
|
|
return m
|
|
}
|
|
|
|
func (m *MockStorage) ExpectRemoveObjectNoError() *MockStorage {
|
|
m.EXPECT().
|
|
RemoveObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
|
Return(nil)
|
|
return m
|
|
}
|
|
|
|
func (m *MockStorage) ExpectRemoveObjectsNoError() *MockStorage {
|
|
m.EXPECT().
|
|
RemoveObjects(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
|
Return(nil)
|
|
return m
|
|
}
|
|
|
|
func (m *MockStorage) ExpectRemoveObjectError() *MockStorage {
|
|
m.EXPECT().
|
|
RemoveObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
|
Return(zerrors.ThrowInternal(nil, "", ""))
|
|
return m
|
|
}
|