feat: instance remove (#4345)

* feat(instance): add remove instance event with projections cleanup

* fix(instance): corrected used id to clean up projections

* fix merge

* fix: correct unit test projection names

* fix: current sequence of lists and query for ensuring keypair based projections

Co-authored-by: Livio Spring <livio.a@gmail.com>
Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com>
This commit is contained in:
Stefan Benz
2022-10-20 13:36:52 +01:00
committed by GitHub
parent 6e89b7d0a1
commit c2a5b785fb
90 changed files with 1549 additions and 427 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/action"
"github.com/zitadel/zitadel/internal/repository/instance"
)
func TestActionProjection_reduces(t *testing.T) {
@@ -33,7 +34,6 @@ func TestActionProjection_reduces(t *testing.T) {
},
reduce: (&actionProjection{}).reduceActionAdded,
want: wantReduce{
projection: ActionTable,
aggregateType: eventstore.AggregateType("action"),
sequence: 15,
previousSequence: 10,
@@ -70,7 +70,6 @@ func TestActionProjection_reduces(t *testing.T) {
},
reduce: (&actionProjection{}).reduceActionChanged,
want: wantReduce{
projection: ActionTable,
aggregateType: eventstore.AggregateType("action"),
sequence: 15,
previousSequence: 10,
@@ -101,7 +100,6 @@ func TestActionProjection_reduces(t *testing.T) {
},
reduce: (&actionProjection{}).reduceActionDeactivated,
want: wantReduce{
projection: ActionTable,
aggregateType: eventstore.AggregateType("action"),
sequence: 15,
previousSequence: 10,
@@ -131,7 +129,6 @@ func TestActionProjection_reduces(t *testing.T) {
},
reduce: (&actionProjection{}).reduceActionReactivated,
want: wantReduce{
projection: ActionTable,
aggregateType: eventstore.AggregateType("action"),
sequence: 15,
previousSequence: 10,
@@ -161,7 +158,6 @@ func TestActionProjection_reduces(t *testing.T) {
},
reduce: (&actionProjection{}).reduceActionRemoved,
want: wantReduce{
projection: ActionTable,
aggregateType: eventstore.AggregateType("action"),
sequence: 15,
previousSequence: 10,
@@ -177,6 +173,32 @@ func TestActionProjection_reduces(t *testing.T) {
},
},
},
{
name: "reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(ActionInstanceIDCol),
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.actions2 WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -188,7 +210,7 @@ func TestActionProjection_reduces(t *testing.T) {
event = tt.args.event(t)
got, err = tt.reduce(event)
assertReduce(t, got, err, tt.want)
assertReduce(t, got, err, ActionTable, tt.want)
})
}
}