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

nil handling for Call() #40

Merged
merged 2 commits into from Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions container.go
Expand Up @@ -150,6 +150,9 @@ func (c Container) Call(function interface{}) error {
if len(result) == 0 {
return nil
} else if len(result) == 1 && result[0].CanInterface() {
if result[0].IsNil() {
return nil
}
if err, ok := result[0].Interface().(error); ok {
return err
}
Expand Down
14 changes: 14 additions & 0 deletions container_test.go
Expand Up @@ -223,6 +223,20 @@ func TestContainer_Call_With_A_Returning_Error(t *testing.T) {
assert.EqualError(t, err, "app: some context error")
}

func TestContainer_Call_With_A_Returning_Nil_Error(t *testing.T) {
instance.Reset()

err := instance.Singleton(func() Shape {
return &Circle{}
})
assert.NoError(t, err)

err = instance.Call(func(s Shape) error {
return nil
})
assert.Nil(t, err)
}

func TestContainer_Call_With_Invalid_Signature(t *testing.T) {
instance.Reset()

Expand Down