mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 03:54:21 +00:00
5811a7b6a5
* refactor(v2): init database package * refactor(v2): init eventstore package * add mock package * test query constructors * option based push analog to query
123 lines
2.0 KiB
Go
123 lines
2.0 KiB
Go
package postgres
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
|
)
|
|
|
|
func Test_checkSequences(t *testing.T) {
|
|
type args struct {
|
|
intents []*intent
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want bool
|
|
}{
|
|
{
|
|
name: "ignore",
|
|
args: args{
|
|
intents: []*intent{
|
|
{
|
|
sequence: 1,
|
|
PushAggregate: eventstore.NewPushAggregate(
|
|
"", "", "",
|
|
eventstore.IgnoreCurrentSequence(),
|
|
),
|
|
},
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "ignores",
|
|
args: args{
|
|
intents: []*intent{
|
|
{
|
|
sequence: 1,
|
|
PushAggregate: eventstore.NewPushAggregate(
|
|
"", "", "",
|
|
eventstore.IgnoreCurrentSequence(),
|
|
),
|
|
},
|
|
{
|
|
sequence: 1,
|
|
PushAggregate: eventstore.NewPushAggregate(
|
|
"", "", "",
|
|
),
|
|
},
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "matches",
|
|
args: args{
|
|
intents: []*intent{
|
|
{
|
|
sequence: 0,
|
|
PushAggregate: eventstore.NewPushAggregate(
|
|
"", "", "",
|
|
eventstore.CurrentSequenceMatches(0),
|
|
),
|
|
},
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "does not match",
|
|
args: args{
|
|
intents: []*intent{
|
|
{
|
|
sequence: 1,
|
|
PushAggregate: eventstore.NewPushAggregate(
|
|
"", "", "",
|
|
eventstore.CurrentSequenceMatches(2),
|
|
),
|
|
},
|
|
},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "at least",
|
|
args: args{
|
|
intents: []*intent{
|
|
{
|
|
sequence: 10,
|
|
PushAggregate: eventstore.NewPushAggregate(
|
|
"", "", "",
|
|
eventstore.CurrentSequenceAtLeast(0),
|
|
),
|
|
},
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "at least too low",
|
|
args: args{
|
|
intents: []*intent{
|
|
{
|
|
sequence: 1,
|
|
PushAggregate: eventstore.NewPushAggregate(
|
|
"", "", "",
|
|
eventstore.CurrentSequenceAtLeast(2),
|
|
),
|
|
},
|
|
},
|
|
},
|
|
want: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := checkSequences(tt.args.intents); got != tt.want {
|
|
t.Errorf("checkSequences() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|