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
+28 -15
View File
@@ -10,6 +10,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/project"
)
@@ -40,7 +41,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -78,7 +78,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -111,7 +110,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -144,7 +142,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -177,7 +174,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -205,7 +201,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -219,6 +214,32 @@ func TestAppProjection_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(AppColumnInstanceID),
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.apps3 WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
{
name: "project.reduceAPIConfigAdded",
args: args{
@@ -238,7 +259,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -283,7 +303,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -324,7 +343,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{},
},
@@ -347,7 +365,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -403,7 +420,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -472,7 +488,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -525,7 +540,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{},
},
@@ -548,7 +562,6 @@ func TestAppProjection_reduces(t *testing.T) {
aggregateType: eventstore.AggregateType("project"),
sequence: 15,
previousSequence: 10,
projection: AppProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -583,7 +596,7 @@ func TestAppProjection_reduces(t *testing.T) {
event = tt.args.event(t)
got, err = tt.reduce(event)
assertReduce(t, got, err, tt.want)
assertReduce(t, got, err, AppProjectionTable, tt.want)
})
}
}