diff --git a/states/statemgr/statemgr_fake.go b/states/statemgr/statemgr_fake.go index 42d2b9bb3..36de10865 100644 --- a/states/statemgr/statemgr_fake.go +++ b/states/statemgr/statemgr_fake.go @@ -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") +}