Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify FailingReactor #930

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 10 additions & 63 deletions pkg/fake/failing_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,79 +54,26 @@ func (f *FailingReactor) react(action testing.Action) (bool, runtime.Object, err
f.mutex.Lock()
defer f.mutex.Unlock()

var fail *error

switch action.GetVerb() {
case "get":
return f.get()
fail = &f.failOnGet
case "create":
return f.create()
fail = &f.failOnCreate
case "update":
return f.update()
fail = &f.failOnUpdate
case "delete":
return f.delete()
fail = &f.failOnDelete
case "list":
return f.list()
}

return false, nil, nil
}

func (f *FailingReactor) get() (bool, runtime.Object, error) {
err := f.failOnGet
if err != nil {
if f.resetOnFailure {
f.failOnGet = nil
}

return true, nil, err
fail = &f.failOnList
}

return false, nil, nil
}

func (f *FailingReactor) create() (bool, runtime.Object, error) {
err := f.failOnCreate
if err != nil {
if f.resetOnFailure {
f.failOnCreate = nil
}

return true, nil, err
}

return false, nil, nil
}

func (f *FailingReactor) update() (bool, runtime.Object, error) {
err := f.failOnUpdate
if err != nil {
if f.resetOnFailure {
f.failOnUpdate = nil
}

return true, nil, err
}

return false, nil, nil
}

func (f *FailingReactor) delete() (bool, runtime.Object, error) {
err := f.failOnDelete
if err != nil {
if f.resetOnFailure {
f.failOnDelete = nil
}

return true, nil, err
}

return false, nil, nil
}
if *fail != nil {
err := *fail

func (f *FailingReactor) list() (bool, runtime.Object, error) {
err := f.failOnList
if err != nil {
if f.resetOnFailure {
f.failOnList = nil
*fail = nil
}

return true, nil, err
Expand Down
Loading