From 14ab07c709ba6821e5c6ae3559c4ba7e66307f0c Mon Sep 17 00:00:00 2001 From: xuans Date: Wed, 30 Sep 2026 12:52:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=B8=85=E7=90=86=E6=B5=8B=E8=AF=95=E5=A4=B9=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加可控的数据库凭据保存和删除失败测试夹具,为后续生命周期回归测试做准备。 --- backend/internal/bootstrap/database_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/internal/bootstrap/database_test.go b/backend/internal/bootstrap/database_test.go index 8e5b894..5d0578d 100644 --- a/backend/internal/bootstrap/database_test.go +++ b/backend/internal/bootstrap/database_test.go @@ -3,6 +3,7 @@ package bootstrap import ( "context" "encoding/json" + "errors" "path/filepath" "strings" "sync" @@ -13,8 +14,10 @@ import ( ) type memoryDatabaseStore struct { - mu sync.Mutex - values map[string]map[string]string + mu sync.Mutex + values map[string]map[string]string + putFailure bool + deleteFailures int } func (s *memoryDatabaseStore) Put(_ context.Context, reference string, value map[string]string) error { @@ -24,6 +27,9 @@ func (s *memoryDatabaseStore) Put(_ context.Context, reference string, value map s.values = make(map[string]map[string]string) } s.values[reference] = map[string]string{"username": value["username"], "password": value["password"]} + if s.putFailure { + return errors.New("simulated put failure") + } return nil } @@ -36,6 +42,10 @@ func (s *memoryDatabaseStore) Get(_ context.Context, reference string) (map[stri func (s *memoryDatabaseStore) Delete(_ context.Context, reference string) error { s.mu.Lock() defer s.mu.Unlock() + if s.deleteFailures > 0 { + s.deleteFailures-- + return errors.New("simulated delete failure") + } delete(s.values, reference) return nil }