Skip to content

Commit

Permalink
Stop Decorator Running When Dry Run Set (#371)
Browse files Browse the repository at this point in the history
Currently, decorators still run even when dry run is set
in the container (see Fx issue: uber-go/fx#1018)

This changes decorators to use the scope's invoker when decorating,
causing it to fill-in zero-valued results instead of actually running the function
when the dry run option is set.
  • Loading branch information
JacobOaks committed Jan 9, 2023
1 parent cdbd7eb commit ddb708f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (n *decoratorNode) Call(s containerStore) (err error) {
}
}

results := reflect.ValueOf(n.dcor).Call(args)
results := s.invoker()(reflect.ValueOf(n.dcor), args)
if err := n.results.ExtractList(n.s, true /* decorated */, results); err != nil {
return err
}
Expand Down
16 changes: 16 additions & 0 deletions dig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,22 @@ func TestDryModeSuccess(t *testing.T) {
c.RequireProvide(provides)
c.RequireInvoke(invokes)
})
t.Run("does not call decorators", func(t *testing.T) {
type type1 struct{}
provides := func() *type1 {
t.Fatal("must not be called")
return &type1{}
}
decorates := func(*type1) *type1 {
t.Fatal("must not be called")
return &type1{}
}
invokes := func(*type1) {}
c := digtest.New(t, dig.DryRun(true))
c.RequireProvide(provides)
c.RequireDecorate(decorates)
c.RequireInvoke(invokes)
})
}

func TestProvideCycleFails(t *testing.T) {
Expand Down

0 comments on commit ddb708f

Please sign in to comment.