-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple ResultTags
annotations
#1225
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1431,7 +1431,7 @@ func TestAnnotate(t *testing.T) { | |
t.Run("specify two ResultTags", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
app := NewForTest(t, | ||
app := fxtest.New(t, | ||
fx.Provide( | ||
// This should just leave newA as it is. | ||
fx.Annotate( | ||
|
@@ -1440,12 +1440,62 @@ func TestAnnotate(t *testing.T) { | |
fx.ResultTags(`name:"AA"`), | ||
), | ||
), | ||
fx.Invoke(newB), | ||
fx.Invoke( | ||
fx.Annotate(func(a, aa *a) (*b, *b) { | ||
return newB(a), newB(aa) | ||
}, fx.ParamTags(`name:"A"`, `name:"AA"`))), | ||
) | ||
|
||
err := app.Err() | ||
require.Error(t, err) | ||
assert.Contains(t, err.Error(), "encountered error while applying annotation using fx.Annotate to go.uber.org/fx_test.TestAnnotate.func1(): cannot apply more than one line of ResultTags") | ||
require.NoError(t, err) | ||
defer app.RequireStart().RequireStop() | ||
}) | ||
|
||
t.Run("specify two ResultTags containing multiple tags", func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a test case for using multiple As annotations and ResultTags annotations. For example, something like the following: fx.Provide(
fx.Annotate(
func() *bytes.Buffer { return bytes.NewBuffer() },
fx.As(new(io.Reader)),
fx.As(new(io.Writer)),
fx.ResultTags(`name:"foo"`),
fx.ResultTags(`name:"bar"`),
)
) In fact, what's the expected behavior in this case? |
||
t.Parallel() | ||
|
||
app := fxtest.New(t, | ||
fx.Provide( | ||
fx.Annotate( | ||
func() (*a, *b) { | ||
return newA(), newB(&a{}) | ||
}, | ||
fx.ResultTags(`name:"A"`, `name:"B"`), | ||
fx.ResultTags(`name:"AA"`, `name:"BB"`), | ||
), | ||
), | ||
fx.Invoke( | ||
fx.Annotate(func(a, aa *a, b, bb *b) (*b, *b, *c, *c) { | ||
return newB(a), newB(aa), newC(b), newC(b) | ||
}, fx.ParamTags(`name:"A"`, `name:"AA"`, `name:"B"`, `name:"BB"`))), | ||
) | ||
|
||
err := app.Err() | ||
require.NoError(t, err) | ||
defer app.RequireStart().RequireStop() | ||
}) | ||
|
||
t.Run("specify Three ResultTags", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
app := fxtest.New(t, | ||
fx.Provide( | ||
fx.Annotate( | ||
newA, | ||
fx.ResultTags(`name:"A"`), | ||
fx.ResultTags(`name:"AA"`), | ||
fx.ResultTags(`name:"AAA"`), | ||
), | ||
), | ||
fx.Invoke( | ||
fx.Annotate(func(a, aa, aaa *a) (*b, *b, *b) { | ||
return newB(a), newB(aa), newB(aaa) | ||
}, fx.ParamTags(`name:"A"`, `name:"AA"`, `name:"AAA"`))), | ||
) | ||
|
||
err := app.Err() | ||
require.NoError(t, err) | ||
defer app.RequireStart().RequireStop() | ||
}) | ||
|
||
t.Run("annotate with a non-nil error", func(t *testing.T) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we validate whether or not a given set of ResultTags annotations will provide conflicting types to the container before we try to build out an actual constructor? (in apply() method) If we validate it beforehand, we won't have to worry about this at all here.