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 <[email protected]>
Co-authored-by: Fabi <[email protected]>
This commit is contained in:
Stefan Benz
2022-10-20 14:36:52 +02:00
committed by GitHub
co-authored by Livio Spring Fabi
parent 6e89b7d0a1
commit c2a5b785fb
90 changed files with 1548 additions and 426 deletions
@@ -8,6 +8,7 @@ import (
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/project"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -40,7 +41,6 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: ProjectMemberProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -77,7 +77,6 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: ProjectMemberProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -110,7 +109,6 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: ProjectMemberProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -140,7 +138,6 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: ProjectMemberProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -168,7 +165,6 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
aggregateType: user.AggregateType,
sequence: 15,
previousSequence: 10,
projection: ProjectMemberProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -195,7 +191,6 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
aggregateType: org.AggregateType,
sequence: 15,
previousSequence: 10,
projection: ProjectMemberProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -208,6 +203,32 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
},
},
},
{
name: "instance.reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
[]byte(`{"name": "Name"}`),
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(MemberInstanceID),
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.project_members2 WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
{
name: "project.ProjectRemovedEventType",
args: args{
@@ -222,7 +243,6 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: ProjectMemberProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -246,7 +266,7 @@ func TestProjectMemberProjection_reduces(t *testing.T) {
event = tt.args.event(t)
got, err = tt.reduce(event)
assertReduce(t, got, err, tt.want)
assertReduce(t, got, err, ProjectMemberProjectionTable, tt.want)
})
}
}