Skip to content

Commit

Permalink
Merge fab43f6 into cc127cb
Browse files Browse the repository at this point in the history
  • Loading branch information
glibsm committed May 30, 2017
2 parents cc127cb + fab43f6 commit edeca35
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dig_test.go
Expand Up @@ -212,6 +212,28 @@ func TestEndToEndSuccess(t *testing.T) {
require.NoError(t, c.Invoke(consumer), "invoke failed")
})

t.Run("multiple-type constructor is called once", func(t *testing.T) {
c := New()
type A struct{}
type B struct{}
count := 0
constructor := func() (*A, *B, error) {
count++
return &A{}, &B{}, nil
}
getA := func(a *A) {
assert.NotNil(t, a, "got nil A")
}
getB := func(b *B) {
assert.NotNil(t, b, "got nil B")
}
require.NoError(t, c.Provide(constructor), "provide failed")
require.NoError(t, c.Invoke(getA), "A invoke failed")
require.NoError(t, c.Invoke(getB), "B invoke failed")
require.NoError(t, c.Invoke(func(a *A, b *B) {}), "AB invoke failed")
require.Equal(t, 1, count, "Constructor must be called once")
})

t.Run("collections and instances of same type", func(t *testing.T) {
c := New()
require.NoError(t, c.Provide(func() []*bytes.Buffer {
Expand Down

0 comments on commit edeca35

Please sign in to comment.