mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:57:32 +00:00
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>
This commit is contained in:
94
internal/migration/step_test.go
Normal file
94
internal/migration/step_test.go
Normal file
@@ -0,0 +1,94 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user