mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-21 23:37:31 +00:00
b5564572bc
This implementation increases parallel write capabilities of the eventstore. Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and [06](https://zitadel.com/docs/support/advisory/a10006). The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`. If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
258 lines
7.4 KiB
Go
258 lines
7.4 KiB
Go
package projection
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
|
"github.com/zitadel/zitadel/internal/repository/instance"
|
|
)
|
|
|
|
func TestDebugNotificationProviderProjection_reduces(t *testing.T) {
|
|
type args struct {
|
|
event func(t *testing.T) eventstore.Event
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
reduce func(event eventstore.Event) (*handler.Statement, error)
|
|
want wantReduce
|
|
}{
|
|
{
|
|
name: "instance reduceNotificationProviderFileAdded",
|
|
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded,
|
|
args: args{
|
|
event: getEvent(
|
|
testEvent(
|
|
instance.DebugNotificationProviderFileAddedEventType,
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"compact": true
|
|
}`),
|
|
), instance.DebugNotificationProviderFileAddedEventMapper),
|
|
},
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "INSERT INTO projections.notification_providers (aggregate_id, creation_date, change_date, sequence, resource_owner, instance_id, state, provider_type, compact) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
anyArg{},
|
|
anyArg{},
|
|
uint64(15),
|
|
"ro-id",
|
|
"instance-id",
|
|
domain.NotificationProviderStateActive,
|
|
domain.NotificationProviderTypeFile,
|
|
true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceNotificationProviderFileChanged",
|
|
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged,
|
|
args: args{
|
|
event: getEvent(
|
|
testEvent(
|
|
instance.DebugNotificationProviderFileChangedEventType,
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"compact": true
|
|
}`),
|
|
), instance.DebugNotificationProviderFileChangedEventMapper),
|
|
},
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5) AND (instance_id = $6)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
true,
|
|
"agg-id",
|
|
domain.NotificationProviderTypeFile,
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceNotificationProviderFileRemoved",
|
|
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved,
|
|
args: args{
|
|
event: getEvent(
|
|
testEvent(
|
|
instance.DebugNotificationProviderFileRemovedEventType,
|
|
instance.AggregateType,
|
|
nil,
|
|
), instance.DebugNotificationProviderFileRemovedEventMapper),
|
|
},
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2) AND (instance_id = $3)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
domain.NotificationProviderTypeFile,
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceNotificationProviderLogAdded",
|
|
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderAdded,
|
|
args: args{
|
|
event: getEvent(
|
|
testEvent(
|
|
instance.DebugNotificationProviderLogAddedEventType,
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"compact": true
|
|
}`),
|
|
), instance.DebugNotificationProviderLogAddedEventMapper),
|
|
},
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "INSERT INTO projections.notification_providers (aggregate_id, creation_date, change_date, sequence, resource_owner, instance_id, state, provider_type, compact) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
anyArg{},
|
|
anyArg{},
|
|
uint64(15),
|
|
"ro-id",
|
|
"instance-id",
|
|
domain.NotificationProviderStateActive,
|
|
domain.NotificationProviderTypeLog,
|
|
true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceNotificationProviderLogChanged",
|
|
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderChanged,
|
|
args: args{
|
|
event: getEvent(
|
|
testEvent(
|
|
instance.DebugNotificationProviderLogChangedEventType,
|
|
instance.AggregateType,
|
|
[]byte(`{
|
|
"compact": true
|
|
}`),
|
|
), instance.DebugNotificationProviderLogChangedEventMapper),
|
|
},
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "UPDATE projections.notification_providers SET (change_date, sequence, compact) = ($1, $2, $3) WHERE (aggregate_id = $4) AND (provider_type = $5) AND (instance_id = $6)",
|
|
expectedArgs: []interface{}{
|
|
anyArg{},
|
|
uint64(15),
|
|
true,
|
|
"agg-id",
|
|
domain.NotificationProviderTypeLog,
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceNotificationProviderLogRemoved",
|
|
reduce: (&debugNotificationProviderProjection{}).reduceDebugNotificationProviderRemoved,
|
|
args: args{
|
|
event: getEvent(
|
|
testEvent(
|
|
instance.DebugNotificationProviderLogRemovedEventType,
|
|
instance.AggregateType,
|
|
nil,
|
|
), instance.DebugNotificationProviderLogRemovedEventMapper),
|
|
},
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.notification_providers WHERE (aggregate_id = $1) AND (provider_type = $2) AND (instance_id = $3)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
domain.NotificationProviderTypeLog,
|
|
"instance-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "instance reduceInstanceRemoved",
|
|
args: args{
|
|
event: getEvent(
|
|
testEvent(
|
|
instance.InstanceRemovedEventType,
|
|
instance.AggregateType,
|
|
nil,
|
|
), instance.InstanceRemovedEventMapper),
|
|
},
|
|
reduce: reduceInstanceRemovedHelper(DebugNotificationProviderInstanceIDCol),
|
|
want: wantReduce{
|
|
aggregateType: eventstore.AggregateType("instance"),
|
|
sequence: 15,
|
|
executer: &testExecuter{
|
|
executions: []execution{
|
|
{
|
|
expectedStmt: "DELETE FROM projections.notification_providers WHERE (instance_id = $1)",
|
|
expectedArgs: []interface{}{
|
|
"agg-id",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
event := baseEvent(t)
|
|
got, err := tt.reduce(event)
|
|
if _, ok := err.(errors.InvalidArgument); !ok {
|
|
t.Errorf("no wrong event mapping: %v, got: %v", err, got)
|
|
}
|
|
|
|
event = tt.args.event(t)
|
|
got, err = tt.reduce(event)
|
|
assertReduce(t, got, err, DebugNotificationProviderTable, tt.want)
|
|
})
|
|
}
|
|
}
|