zitadel/internal/migration/step_test.go
Silvan a5d4b08a99
fix(cleanup): cleanup all stuck states (#7145)
* fix(setup): unmarshal of failed step

* fix(cleanup): cleanup all stuck states

* use lastRun for repeatable steps

* typo

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
2024-01-05 09:01:48 +00:00

95 lines
1.7 KiB
Go

package migration
import (
"reflect"
"testing"
"time"
"github.com/zitadel/zitadel/internal/eventstore"
)
func TestStepStates_lastByState(t *testing.T) {
now := time.Now()
past := now.Add(-10 * time.Millisecond)
tests := []struct {
name string
fields *StepStates
arg StepState
want *Step
}{
{
name: "no events reduced invalid state",
fields: &StepStates{},
arg: -1,
},
{
name: "no events reduced by valid state",
fields: &StepStates{},
arg: StepDone,
},
{
name: "no state found",
fields: &StepStates{
Steps: []*Step{
{
SetupStep: &SetupStep{
Name: "done",
},
state: StepDone,
},
{
SetupStep: &SetupStep{
Name: "failed",
},
state: StepFailed,
},
},
},
arg: StepStarted,
},
{
name: "found",
fields: &StepStates{
Steps: []*Step{
{
SetupStep: &SetupStep{
BaseEvent: eventstore.BaseEvent{
Creation: past,
},
},
state: StepStarted,
},
{
SetupStep: &SetupStep{
BaseEvent: eventstore.BaseEvent{
Creation: now,
},
},
state: StepStarted,
},
},
},
arg: StepStarted,
want: &Step{
state: StepStarted,
SetupStep: &SetupStep{
BaseEvent: eventstore.BaseEvent{
Creation: now,
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &StepStates{
ReadModel: tt.fields.ReadModel,
Steps: tt.fields.Steps,
}
if gotStep := s.lastByState(tt.arg); !reflect.DeepEqual(gotStep, tt.want) {
t.Errorf("StepStates.lastByState() = %v, want %v", *gotStep, *tt.want)
}
})
}
}