Files
RenewCMS/test/fakes_common.go
T

55 lines
923 B
Go

package test
import (
"errors"
"sync"
)
var errRepositoryFailure = errors.New("repository failure")
var errRunawayLocking = errors.New("the use case kept locking sites without settling")
const runawayLockCalls = 1000
type failSwitch struct {
method string
err error
}
func (f *failSwitch) failNext(method string) {
f.method = method
f.err = nil
}
func (f *failSwitch) failNextWith(method string, err error) {
f.method = method
f.err = err
}
func (f *failSwitch) trigger(method string) error {
if f.method == method {
f.method = ""
if f.err != nil {
err := f.err
f.err = nil
return err
}
return errRepositoryFailure
}
return nil
}
const migrationPublicURL = "https://www.example.com"
func outsideLock(mu *sync.Mutex, hook func()) {
mu.Unlock()
defer mu.Lock()
hook()
}
func outsideLockErr(mu *sync.Mutex, hook func() error) error {
mu.Unlock()
defer mu.Lock()
return hook()
}