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

@@ -9,6 +9,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"
"github.com/zitadel/zitadel/internal/repository/user"
"github.com/zitadel/zitadel/internal/repository/usergrant"
@@ -42,7 +43,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: usergrant.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -81,7 +81,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: usergrant.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -113,7 +112,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: usergrant.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -143,7 +141,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: usergrant.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -156,6 +153,32 @@ func TestUserGrantProjection_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(UserGrantInstanceID),
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.user_grants2 WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"agg-id",
},
},
},
},
},
},
{
name: "reduceCascadeRemoved",
args: args{
@@ -170,7 +193,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: usergrant.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -197,7 +219,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: usergrant.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -227,7 +248,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: usergrant.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -257,7 +277,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: user.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -284,7 +303,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -311,7 +329,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -338,7 +355,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -366,7 +382,6 @@ func TestUserGrantProjection_reduces(t *testing.T) {
aggregateType: project.AggregateType,
sequence: 15,
previousSequence: 10,
projection: UserGrantProjectionTable,
executer: &testExecuter{
executions: []execution{
{
@@ -391,7 +406,7 @@ func TestUserGrantProjection_reduces(t *testing.T) {
event = tt.args.event(t)
got, err = tt.reduce(event)
assertReduce(t, got, err, tt.want)
assertReduce(t, got, err, UserGrantProjectionTable, tt.want)
})
}
}