mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +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,6 +1,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
@@ -782,9 +783,9 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
|
||||
storage static.Storage
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
orgID string
|
||||
storageKey string
|
||||
ctx context.Context
|
||||
orgID string
|
||||
upload *AssetUpload
|
||||
}
|
||||
type res struct {
|
||||
want *domain.ObjectDetails
|
||||
@@ -803,24 +804,17 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
storageKey: "key",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "storage key empty, invalid argument error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
orgID: "",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
@@ -835,14 +829,63 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "upload failed, error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObjectError(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "logo added, ok",
|
||||
fields: fields{
|
||||
@@ -871,17 +914,25 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyLogoAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"key",
|
||||
"logo",
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObject(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -896,7 +947,7 @@ func TestCommandSide_AddLogoLabelPolicy(t *testing.T) {
|
||||
eventstore: tt.fields.eventstore,
|
||||
static: tt.fields.storage,
|
||||
}
|
||||
got, err := r.AddLogoLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.storageKey)
|
||||
got, err := r.AddLogoLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.upload)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -1039,11 +1090,12 @@ func TestCommandSide_RemoveLogoLabelPolicy(t *testing.T) {
|
||||
func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore *eventstore.Eventstore
|
||||
storage static.Storage
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
orgID string
|
||||
storageKey string
|
||||
ctx context.Context
|
||||
orgID string
|
||||
upload *AssetUpload
|
||||
}
|
||||
type res struct {
|
||||
want *domain.ObjectDetails
|
||||
@@ -1062,24 +1114,17 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
storageKey: "key",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "storage key empty, invalid argument error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
orgID: "",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
@@ -1094,14 +1139,63 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "upload failed, error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObjectError(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "icon added, ok",
|
||||
fields: fields{
|
||||
@@ -1130,17 +1224,25 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyIconAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"key",
|
||||
"icon",
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObject(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -1153,8 +1255,9 @@ func TestCommandSide_AddIconLabelPolicy(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
static: tt.fields.storage,
|
||||
}
|
||||
got, err := r.AddIconLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.storageKey)
|
||||
got, err := r.AddIconLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.upload)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -1294,11 +1397,12 @@ func TestCommandSide_RemoveIconLabelPolicy(t *testing.T) {
|
||||
func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore *eventstore.Eventstore
|
||||
storage static.Storage
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
orgID string
|
||||
storageKey string
|
||||
ctx context.Context
|
||||
orgID string
|
||||
upload *AssetUpload
|
||||
}
|
||||
type res struct {
|
||||
want *domain.ObjectDetails
|
||||
@@ -1319,22 +1423,15 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "storage key empty, invalid argument error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
orgID: "",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
@@ -1349,14 +1446,63 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "upload failed, error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObjectError(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "logo dark added, ok",
|
||||
fields: fields{
|
||||
@@ -1385,17 +1531,25 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyLogoDarkAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"key",
|
||||
"logo",
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObject(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "logo",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -1408,8 +1562,9 @@ func TestCommandSide_AddLogoDarkLabelPolicy(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
static: tt.fields.storage,
|
||||
}
|
||||
got, err := r.AddLogoDarkLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.storageKey)
|
||||
got, err := r.AddLogoDarkLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.upload)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -1555,9 +1710,9 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
|
||||
storage static.Storage
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
orgID string
|
||||
storageKey string
|
||||
ctx context.Context
|
||||
orgID string
|
||||
upload *AssetUpload
|
||||
}
|
||||
type res struct {
|
||||
want *domain.ObjectDetails
|
||||
@@ -1576,24 +1731,17 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
storageKey: "key",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "storage key empty, invalid argument error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
orgID: "",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
@@ -1608,14 +1756,63 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "upload failed, error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObjectError(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "icon dark added, ok",
|
||||
fields: fields{
|
||||
@@ -1644,17 +1841,25 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyIconDarkAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"key",
|
||||
"icon",
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObject(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "icon",
|
||||
ContentType: "image",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -1667,8 +1872,9 @@ func TestCommandSide_AddIconDarkLabelPolicy(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
static: tt.fields.storage,
|
||||
}
|
||||
got, err := r.AddIconDarkLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.storageKey)
|
||||
got, err := r.AddIconDarkLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.upload)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -1806,11 +2012,12 @@ func TestCommandSide_RemoveIconDarkLabelPolicy(t *testing.T) {
|
||||
func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
|
||||
type fields struct {
|
||||
eventstore *eventstore.Eventstore
|
||||
storage static.Storage
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
orgID string
|
||||
storageKey string
|
||||
ctx context.Context
|
||||
orgID string
|
||||
upload *AssetUpload
|
||||
}
|
||||
type res struct {
|
||||
want *domain.ObjectDetails
|
||||
@@ -1829,24 +2036,17 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
storageKey: "key",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "storage key empty, invalid argument error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
orgID: "",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "font",
|
||||
ContentType: "ttf",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsErrorInvalidArgument,
|
||||
@@ -1861,14 +2061,55 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
|
||||
),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsNotFound,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "upload failed, error",
|
||||
fields: fields{
|
||||
eventstore: eventstoreExpect(
|
||||
t,
|
||||
expectFilter(
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
"#ffffff",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObjectError(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "font",
|
||||
ContentType: "ttf",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
err: caos_errs.IsInternal,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "font added, ok",
|
||||
fields: fields{
|
||||
@@ -1897,17 +2138,25 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
|
||||
eventFromEventPusher(
|
||||
org.NewLabelPolicyFontAddedEvent(context.Background(),
|
||||
&org.NewAggregate("org1", "org1").Aggregate,
|
||||
"key",
|
||||
"font",
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
storage: mock.NewStorage(t).ExpectPutObject(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
storageKey: "key",
|
||||
ctx: context.Background(),
|
||||
orgID: "org1",
|
||||
upload: &AssetUpload{
|
||||
ResourceOwner: "org1",
|
||||
ObjectName: "font",
|
||||
ContentType: "ttf",
|
||||
ObjectType: static.ObjectTypeStyling,
|
||||
File: bytes.NewReader([]byte("test")),
|
||||
Size: 4,
|
||||
},
|
||||
},
|
||||
res: res{
|
||||
want: &domain.ObjectDetails{
|
||||
@@ -1920,8 +2169,9 @@ func TestCommandSide_AddFontLabelPolicy(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &Commands{
|
||||
eventstore: tt.fields.eventstore,
|
||||
static: tt.fields.storage,
|
||||
}
|
||||
got, err := r.AddFontLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.storageKey)
|
||||
got, err := r.AddFontLabelPolicy(tt.args.ctx, tt.args.orgID, tt.args.upload)
|
||||
if tt.res.err == nil {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user