statemgr: add a NewUnlockErrorFull state manager for tests (#25823)
* statemgr: add a NewUnlockErrorFull state manager for tests I've frequently needed to coerce Unlock() errors for tests and it's been awkward and fraught every time, so I decided to add a full state manger that returns *mostly* errors. I intend to use this in conjunction with the clistate.Locker interface, which first calls Lock() (to block if the mutex is in use) at the start of Unlock(), so Lock() rather awkwardly needed to succeed.
This commit is contained in:
parent
c9f710ac29
commit
95eca06782
|
@ -94,3 +94,39 @@ func (m *fakeFull) Unlock(id string) error {
|
|||
m.locked = false
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewUnlockErrorFull returns a state manager that is useful for testing errors
|
||||
// (mostly Unlock errors) when used with the clistate.Locker interface. Lock()
|
||||
// does not return an error because clistate.Locker Lock()s the state at the
|
||||
// start of Unlock(), so Lock() must succeeded for Unlock() to get called.
|
||||
func NewUnlockErrorFull(t Transient, initial *states.State) Full {
|
||||
return &fakeErrorFull{}
|
||||
}
|
||||
|
||||
type fakeErrorFull struct{}
|
||||
|
||||
var _ Full = (*fakeErrorFull)(nil)
|
||||
|
||||
func (m *fakeErrorFull) State() *states.State {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *fakeErrorFull) WriteState(s *states.State) error {
|
||||
return errors.New("fake state manager error")
|
||||
}
|
||||
|
||||
func (m *fakeErrorFull) RefreshState() error {
|
||||
return errors.New("fake state manager error")
|
||||
}
|
||||
|
||||
func (m *fakeErrorFull) PersistState() error {
|
||||
return errors.New("fake state manager error")
|
||||
}
|
||||
|
||||
func (m *fakeErrorFull) Lock(info *LockInfo) (string, error) {
|
||||
return "placeholder", nil
|
||||
}
|
||||
|
||||
func (m *fakeErrorFull) Unlock(id string) error {
|
||||
return errors.New("fake state manager error")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue