mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +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.
129 lines
2.4 KiB
Go
129 lines
2.4 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
)
|
|
|
|
func Test_commandToEvent(t *testing.T) {
|
|
payload := struct {
|
|
ID string
|
|
}{
|
|
ID: "test",
|
|
}
|
|
payloadMarshalled, err := json.Marshal(payload)
|
|
if err != nil {
|
|
t.Fatalf("marshal of payload failed: %v", err)
|
|
}
|
|
type args struct {
|
|
sequence *latestSequence
|
|
command eventstore.Command
|
|
}
|
|
type want struct {
|
|
event *event
|
|
err func(t *testing.T, err error)
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want want
|
|
}{
|
|
{
|
|
name: "no payload",
|
|
args: args{
|
|
sequence: &latestSequence{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
sequence: 0,
|
|
},
|
|
command: &mockCommand{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
payload: nil,
|
|
},
|
|
},
|
|
want: want{
|
|
event: mockEvent(
|
|
mockAggregate("V3-Red9I"),
|
|
0,
|
|
nil,
|
|
).(*event),
|
|
},
|
|
},
|
|
{
|
|
name: "struct payload",
|
|
args: args{
|
|
sequence: &latestSequence{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
sequence: 0,
|
|
},
|
|
command: &mockCommand{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
payload: payload,
|
|
},
|
|
},
|
|
want: want{
|
|
event: mockEvent(
|
|
mockAggregate("V3-Red9I"),
|
|
0,
|
|
payloadMarshalled,
|
|
).(*event),
|
|
},
|
|
},
|
|
{
|
|
name: "pointer payload",
|
|
args: args{
|
|
sequence: &latestSequence{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
sequence: 0,
|
|
},
|
|
command: &mockCommand{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
payload: &payload,
|
|
},
|
|
},
|
|
want: want{
|
|
event: mockEvent(
|
|
mockAggregate("V3-Red9I"),
|
|
0,
|
|
payloadMarshalled,
|
|
).(*event),
|
|
},
|
|
},
|
|
{
|
|
name: "invalid payload",
|
|
args: args{
|
|
sequence: &latestSequence{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
sequence: 0,
|
|
},
|
|
command: &mockCommand{
|
|
aggregate: mockAggregate("V3-Red9I"),
|
|
payload: func() {},
|
|
},
|
|
},
|
|
want: want{
|
|
err: func(t *testing.T, err error) {
|
|
assert.Error(t, err)
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
if tt.want.err == nil {
|
|
tt.want.err = func(t *testing.T, err error) {
|
|
require.NoError(t, err)
|
|
}
|
|
}
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := commandToEvent(tt.args.sequence, tt.args.command)
|
|
|
|
tt.want.err(t, err)
|
|
assert.Equal(t, tt.want.event, got)
|
|
})
|
|
}
|
|
}
|