mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 12:27:59 +00:00
b5564572bc
This implementation increases parallel write capabilities of the eventstore. Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and [06](https://zitadel.com/docs/support/advisory/a10006). The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`. If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
60 lines
2.1 KiB
Go
60 lines
2.1 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"reflect"
|
|
"testing"
|
|
|
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
es_model "github.com/zitadel/zitadel/internal/project/repository/eventsourcing/model"
|
|
"github.com/zitadel/zitadel/internal/repository/project"
|
|
)
|
|
|
|
func mockProjectMemberData(member *es_model.ProjectMember) []byte {
|
|
data, _ := json.Marshal(member)
|
|
return data
|
|
}
|
|
|
|
func TestProjectMemberAppendEvent(t *testing.T) {
|
|
type args struct {
|
|
event *es_models.Event
|
|
member *ProjectMemberView
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *ProjectMemberView
|
|
}{
|
|
{
|
|
name: "append added member event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.MemberAddedType, ResourceOwner: "OrgID", Data: mockProjectMemberData(&es_model.ProjectMember{UserID: "UserID", Roles: []string{"Role"}})},
|
|
member: &ProjectMemberView{},
|
|
},
|
|
result: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: []string{"Role"}},
|
|
},
|
|
{
|
|
name: "append changed member event",
|
|
args: args{
|
|
event: &es_models.Event{AggregateID: "AggregateID", Seq: 1, Typ: project.MemberAddedType, ResourceOwner: "OrgID", Data: mockProjectMemberData(&es_model.ProjectMember{UserID: "UserID", Roles: []string{"RoleChanged"}})},
|
|
member: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: []string{"Role"}},
|
|
},
|
|
result: &ProjectMemberView{ProjectID: "AggregateID", UserID: "UserID", Roles: []string{"RoleChanged"}},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.args.member.AppendEvent(tt.args.event)
|
|
if tt.args.member.ProjectID != tt.result.ProjectID {
|
|
t.Errorf("got wrong result projectID: expected: %v, actual: %v ", tt.result.ProjectID, tt.args.member.ProjectID)
|
|
}
|
|
if tt.args.member.UserID != tt.result.UserID {
|
|
t.Errorf("got wrong result userID: expected: %v, actual: %v ", tt.result.UserID, tt.args.member.UserID)
|
|
}
|
|
if !reflect.DeepEqual(tt.args.member.Roles, tt.result.Roles) {
|
|
t.Errorf("got wrong result Roles: expected: %v, actual: %v ", tt.result.Roles, tt.args.member.Roles)
|
|
}
|
|
})
|
|
}
|
|
}
|