func TestExtractByTypeNoMatch(t *testing.T) { RegisterTestingT(t) graph := inject.NewGraph() var ( b1 *beta g1 *gamma ) graph.Define(&b1, inject.NewProvider(func() *beta { return &beta{name: "b1"} })) graph.Define(&g1, inject.NewProvider(func() *gamma { return &gamma{name: "g1"} })) var a *alpha defer ExpectPanic("no defined pointer matches the specified type") inject.ExtractByType(graph, &a) }
func TestExtractByType(t *testing.T) { RegisterTestingT(t) graph := inject.NewGraph() var ( a1 *alpha b1 *beta g1 *gamma ) graph.Define(&a1, inject.NewProvider(func() *alpha { return &alpha{name: "a1"} })) graph.Define(&b1, inject.NewProvider(func() *beta { return &beta{name: "b1"} })) graph.Define(&g1, inject.NewProvider(func() *gamma { return &gamma{name: "g1"} })) var a *alpha inject.ExtractByType(graph, &a) Expect(a).To(Equal(&alpha{name: "a1"})) }