补充数据库清理测试夹具
增加可控的数据库凭据保存和删除失败测试夹具,为后续生命周期回归测试做准备。
This commit is contained in:
parent
41a111165a
commit
14ab07c709
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user