mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
56b916a2b0
* begin init checks for projections * first projection checks * debug notification providers with query fixes * more projections and first index * more projections * more projections * finish projections * fix tests (remove db name) * create tables in setup * fix logging / error handling * add tenant to views * rename tenant to instance_id * add instance_id to all projections * add instance_id to all queries * correct instance_id on projections * add instance_id to failed_events * use separate context for instance * implement features projection * implement features projection * remove unique constraint from setup when migration failed * add error to failed setup event * add instance_id to primary keys * fix IAM projection * remove old migrations folder * fix keysFromYAML test
90 lines
2.5 KiB
Go
90 lines
2.5 KiB
Go
package projection
|
|
|
|
import (
|
|
"database/sql"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/eventstore/handler"
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
)
|
|
|
|
func testEvent(
|
|
eventType repository.EventType,
|
|
aggregateType repository.AggregateType,
|
|
data []byte,
|
|
) *repository.Event {
|
|
return &repository.Event{
|
|
Sequence: 15,
|
|
PreviousAggregateSequence: 10,
|
|
PreviousAggregateTypeSequence: 10,
|
|
CreationDate: time.Now(),
|
|
Type: eventType,
|
|
AggregateType: aggregateType,
|
|
Data: data,
|
|
Version: "v1",
|
|
AggregateID: "agg-id",
|
|
ResourceOwner: sql.NullString{String: "ro-id", Valid: true},
|
|
InstanceID: sql.NullString{String: "instance-id", Valid: true},
|
|
ID: "event-id",
|
|
EditorService: "editor-svc",
|
|
EditorUser: "editor-user",
|
|
}
|
|
}
|
|
|
|
func baseEvent(*testing.T) eventstore.Event {
|
|
return &eventstore.BaseEvent{}
|
|
}
|
|
|
|
func getEvent(event *repository.Event, mapper func(*repository.Event) (eventstore.Event, error)) func(t *testing.T) eventstore.Event {
|
|
return func(t *testing.T) eventstore.Event {
|
|
e, err := mapper(event)
|
|
if err != nil {
|
|
t.Fatalf("mapper failed: %v", err)
|
|
}
|
|
return e
|
|
}
|
|
}
|
|
|
|
type wantReduce struct {
|
|
projection string
|
|
aggregateType eventstore.AggregateType
|
|
sequence uint64
|
|
previousSequence uint64
|
|
executer *testExecuter
|
|
err func(error) bool
|
|
}
|
|
|
|
func assertReduce(t *testing.T, stmt *handler.Statement, err error, want wantReduce) {
|
|
t.Helper()
|
|
if want.err == nil && err != nil {
|
|
t.Errorf("unexpected error of type %T: %v", err, err)
|
|
return
|
|
}
|
|
if want.err != nil && want.err(err) {
|
|
return
|
|
}
|
|
if stmt.AggregateType != want.aggregateType {
|
|
t.Errorf("wrong aggregate type: want: %q got: %q", want.aggregateType, stmt.AggregateType)
|
|
}
|
|
|
|
if stmt.PreviousSequence != want.previousSequence {
|
|
t.Errorf("wrong previous sequence: want: %d got: %d", want.previousSequence, stmt.PreviousSequence)
|
|
}
|
|
|
|
if stmt.Sequence != want.sequence {
|
|
t.Errorf("wrong sequence: want: %d got: %d", want.sequence, stmt.Sequence)
|
|
}
|
|
if stmt.Execute == nil {
|
|
want.executer.Validate(t)
|
|
return
|
|
}
|
|
err = stmt.Execute(want.executer, want.projection)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
|
|
want.executer.Validate(t)
|
|
}
|