package persistence import ( "testing" ) func TestPersistenceStrategy_String(t *testing.T) { tests := []struct { name string strategy PersistenceStrategy expected string }{ {"db only", StrategyDBOnly, "DB_ONLY"}, {"db and trustlog", StrategyDBAndTrustlog, "DB_AND_TRUSTLOG"}, {"trustlog only", StrategyTrustlogOnly, "TRUSTLOG_ONLY"}, {"unknown", PersistenceStrategy(999), "UNKNOWN"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := tt.strategy.String() if result != tt.expected { t.Errorf("expected %s, got %s", tt.expected, result) } }) } } func TestDefaultPersistenceConfig(t *testing.T) { tests := []struct { name string strategy PersistenceStrategy }{ {"db only", StrategyDBOnly}, {"db and trustlog", StrategyDBAndTrustlog}, {"trustlog only", StrategyTrustlogOnly}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { config := DefaultPersistenceConfig(tt.strategy) if config.Strategy != tt.strategy { t.Errorf("expected strategy %v, got %v", tt.strategy, config.Strategy) } if !config.EnableRetry { t.Error("expected EnableRetry to be true by default") } if config.MaxRetryCount != 5 { t.Errorf("expected MaxRetryCount to be 5, got %d", config.MaxRetryCount) } if config.RetryBatchSize != 100 { t.Errorf("expected RetryBatchSize to be 100, got %d", config.RetryBatchSize) } }) } } func TestPersistenceConfig_CustomValues(t *testing.T) { config := PersistenceConfig{ Strategy: StrategyDBAndTrustlog, EnableRetry: false, MaxRetryCount: 10, RetryBatchSize: 200, } if config.Strategy != StrategyDBAndTrustlog { t.Errorf("expected strategy StrategyDBAndTrustlog, got %v", config.Strategy) } if config.EnableRetry { t.Error("expected EnableRetry to be false") } if config.MaxRetryCount != 10 { t.Errorf("expected MaxRetryCount to be 10, got %d", config.MaxRetryCount) } if config.RetryBatchSize != 200 { t.Errorf("expected RetryBatchSize to be 200, got %d", config.RetryBatchSize) } }