mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
feat: store assets in database (#3290)
* feat: use database as asset storage * being only uploading assets if allowed * tests * fixes * cleanup after merge * renaming * various fixes * fix: change to repository event types and removed unused code * feat: set default features * error handling * error handling and naming * fix tests * fix tests * fix merge * rename
This commit is contained in:
@@ -1,34 +1,49 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
|
||||
caos_errors "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/static"
|
||||
)
|
||||
|
||||
func NewStorage(t *testing.T) *MockStorage {
|
||||
return NewMockStorage(gomock.NewController(t))
|
||||
}
|
||||
|
||||
func (m *MockStorage) ExpectAddObjectNoError() *MockStorage {
|
||||
func (m *MockStorage) ExpectPutObject() *MockStorage {
|
||||
m.EXPECT().
|
||||
PutObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
Return(nil, nil)
|
||||
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) ExpectAddObjectError() *MockStorage {
|
||||
func (m *MockStorage) ExpectPutObjectError() *MockStorage {
|
||||
m.EXPECT().
|
||||
PutObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
PutObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
Return(nil, caos_errors.ThrowInternal(nil, "", ""))
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockStorage) ExpectRemoveObjectNoError() *MockStorage {
|
||||
m.EXPECT().
|
||||
RemoveObject(gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
RemoveObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
Return(nil)
|
||||
return m
|
||||
}
|
||||
@@ -42,7 +57,7 @@ func (m *MockStorage) ExpectRemoveObjectsNoError() *MockStorage {
|
||||
|
||||
func (m *MockStorage) ExpectRemoveObjectError() *MockStorage {
|
||||
m.EXPECT().
|
||||
RemoveObject(gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
RemoveObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
Return(caos_errors.ThrowInternal(nil, "", ""))
|
||||
return m
|
||||
}
|
||||
|
Reference in New Issue
Block a user