test(eventstore): push

This commit is contained in:
adlerhurst
2020-10-15 08:44:17 +02:00
parent 639872b82e
commit d400b02e53
2 changed files with 78 additions and 8 deletions
@@ -1,6 +1,7 @@
package sql
import (
"context"
"testing"
"github.com/caos/zitadel/internal/eventstore/v2/repository"
@@ -260,3 +261,72 @@ func TestCRDB_columnName(t *testing.T) {
})
}
}
func TestCRDB_Push(t *testing.T) {
type args struct {
events []*repository.Event
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "push no events",
args: args{
events: []*repository.Event{},
},
wantErr: false,
},
{
name: "push 1 event with check previous",
args: args{
events: []*repository.Event{
{
// AggregateID: t.Name(),
AggregateType: "test",
CheckPreviousSequence: true,
EditorService: "svc",
EditorUser: "user",
PreviousEvent: nil,
PreviousSequence: 0,
ResourceOwner: "ro",
Type: "test.created",
Version: "v1",
},
},
},
wantErr: false,
},
{
name: "push 1 event with check previous wrong sequence",
args: args{
events: []*repository.Event{
{
// AggregateID: t.Name(),
AggregateType: "test",
CheckPreviousSequence: true,
EditorService: "svc",
EditorUser: "user",
PreviousEvent: nil,
PreviousSequence: 5,
ResourceOwner: "ro",
Type: "test.created",
Version: "v1",
},
},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
db := &CRDB{
client: testCRDBClient,
}
if err := db.Push(context.Background(), tt.args.events...); (err != nil) != tt.wantErr {
t.Errorf("CRDB.Push() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}