Skip to content

Commit

Permalink
Addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anuptalwalkar committed May 18, 2017
1 parent 09d7853 commit 427b672
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Container struct {
graph.Graph
}

// InvokeOnce only allows function invokation once to register the
// InvokeOnce only allows function invocation once to register the
// return types. If return types are already registered, specific error
// is returned to the caller
func (c *Container) InvokeOnce(t interface{}) error {
Expand Down
6 changes: 5 additions & 1 deletion internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,16 @@ func (g *Graph) InsertConstructor(ctor interface{}) error {
}

// ValidateReturnTypes validates if Invoke func's return type is Provided to the graph
// checkCachedObjects=true additionally checks if objects are resolved and cached in the graph
// checkCachedObjects=true ensures to throw an error only when the node is already
// resolved and cached.
//
func (g *Graph) ValidateReturnTypes(ctype reflect.Type, checkCachedObjects bool) error {
objMap := make(map[reflect.Type]bool, ctype.NumOut())
for i := 0; i < ctype.NumOut(); i++ {
objType := ctype.Out(i)
if _, ok := g.nodes[objType]; ok {
// for Invoke validation, graphNode may not be resolved (still in the form of funcNode).
// checkCachedObjects ensures to throw an error only when the node is resolved and cached.
if checkCachedObjects {
if obj, ok := g.nodes[objType].(*objNode); ok && obj.cached {
return errors.Wrapf(errRetNode, "ctor: %v, object type: %v", ctype, objType)
Expand Down
2 changes: 1 addition & 1 deletion internal/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestCtorConflicts(t *testing.T) {
require.Contains(t, err.Error(), "ctor: func() (*graph.Child1, *graph.Child1, error), object type: *graph.Child1: node already exist for the constructor")
}

func TestValidateReturnTypes(t *testing.T) {
func TestConstructorOverrideReturnsError(t *testing.T) {
t.Parallel()
g := NewGraph()

Expand Down

0 comments on commit 427b672

Please sign in to comment.