fix startup bootstrap recovery and local verification

This commit is contained in:
2026-04-23 10:27:13 +08:00
parent 32b2c23a04
commit fa0aacc559
9 changed files with 211 additions and 59 deletions

View File

@@ -1,6 +1,8 @@
package main
import (
"context"
"errors"
"testing"
"time"
@@ -83,3 +85,47 @@ func TestProvideCleanup_WithMinimalDependencies_NoPanic(t *testing.T) {
cleanup()
})
}
func TestNewBootstrapFunc_RunsDefaultsBeforeRecovery(t *testing.T) {
cfg := &config.Config{}
order := make([]string, 0, 2)
bootstrap := newBootstrapFunc(
func(context.Context) error {
order = append(order, "defaults")
return nil
},
func(_ context.Context, gotRepo service.UserRepository, got *config.Config) error {
require.Nil(t, gotRepo)
require.Same(t, cfg, got)
order = append(order, "recover")
return nil
},
nil,
cfg,
)
require.NoError(t, bootstrap())
require.Equal(t, []string{"defaults", "recover"}, order)
}
func TestNewBootstrapFunc_StopsWhenDefaultsFail(t *testing.T) {
cfg := &config.Config{}
wantErr := errors.New("defaults failed")
recoverCalled := false
bootstrap := newBootstrapFunc(
func(context.Context) error {
return wantErr
},
func(context.Context, service.UserRepository, *config.Config) error {
recoverCalled = true
return nil
},
nil,
cfg,
)
require.ErrorIs(t, bootstrap(), wantErr)
require.False(t, recoverCalled)
}