Skip to content

Commit

Permalink
Remove checks for complete graphs, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay Shah committed May 25, 2017
1 parent c81338a commit 0428135
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 42 deletions.
22 changes: 0 additions & 22 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,28 +403,6 @@ func TestInvokeReturnedError(t *testing.T) {
assert.NoError(t, err)
}

func TestInvokeFailureUnresolvedDependencies(t *testing.T) {
t.Parallel()
c := New()

err := c.Provide(
NewParent1,
)
assert.NoError(t, err)

err = c.Invoke(func(p1 *Parent1) {})
require.Contains(t, err.Error(), "unable to resolve *dig.Parent1")

var zeroP12 *Parent12
err = c.Invoke(func(p12 *Parent12) {
zeroP12 = p12
})
require.NoError(t, err)
newZeroP12, ok := reflect.Zero(reflect.TypeOf(zeroP12)).Interface().(*Parent12)
require.True(t, ok)
assert.Equal(t, zeroP12, newZeroP12)
}

func TestProvide(t *testing.T) {
t.Parallel()
c := New()
Expand Down
12 changes: 0 additions & 12 deletions internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,6 @@ func (g *Graph) recursiveDetectCycles(n graphNode, l []string) error {
return nil
}

func (g *Graph) validateGraph(ct reflect.Type) (reflect.Value, error) {
for _, node := range g.nodes {
for _, dep := range node.dependencies() {
// check that the dependency is a registered objNode
if _, ok := g.nodes[dep]; !ok {
return reflect.Zero(ct), nil
}
}
}
return reflect.Zero(ct), nil
}

// ConstructorArguments returns arguments in the provided constructor
func (g *Graph) ConstructorArguments(ctype reflect.Type) ([]reflect.Value, error) {
// find dependencies from the graph and place them in the args
Expand Down
8 changes: 0 additions & 8 deletions internal/graph/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ func (n *funcNode) value(g *Graph, objType reflect.Type) (reflect.Value, error)
}

ct := reflect.TypeOf(n.constructor)

// check that all the dependencies have nodes present in the graph
// doesn't mean everything will go smoothly during resolve, but it
// drastically increases the chances that we're not missing something
if v, err := g.validateGraph(ct); err != nil {
return v, err
}

args, err := g.ConstructorArguments(ct)
if err != nil {
return reflect.Zero(objType), err
Expand Down

0 comments on commit 0428135

Please sign in to comment.