MCPcopy
hub / github.com/uber-go/fx / TestAnnotatedFromFailures

Function TestAnnotatedFromFailures

annotated_test.go:294–427  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

292}
293
294func TestAnnotatedFromFailures(t *testing.T) {
295 t.Parallel()
296 type myStringer interface {
297 String() string
298 }
299
300 newFromStringer := func() *fromStringer {
301 return &fromStringer{name: "stringer"}
302 }
303
304 tests := []struct {
305 desc string
306 provide fx.Option
307 invoke interface{}
308 errorContains string
309 }{
310 {
311 desc: "provide when an illegal type From",
312 provide: fx.Provide(
313 fx.Annotate(
314 func(writer io.Writer) fmt.Stringer {
315 return &fromStringer{}
316 },
317 fx.From(new(*fromStringer)),
318 ),
319 ),
320 invoke: func(stringer fmt.Stringer) {
321 fmt.Println(stringer.String())
322 },
323 errorContains: "*fx_test.fromStringer does not implement io.Writer",
324 },
325 {
326 desc: "provide with variadic function and an illegal type From",
327 provide: fx.Provide(
328 fx.Annotate(
329 func(writer io.Writer, x ...int) fmt.Stringer {
330 return &fromStringer{}
331 },
332 fx.From(new(*fromStringer)),
333 ),
334 ),
335 invoke: func(stringer fmt.Stringer) {
336 fmt.Println(stringer.String())
337 },
338 errorContains: "*fx_test.fromStringer does not implement io.Writer",
339 },
340 {
341 desc: "don't provide original type using From",
342 provide: fx.Provide(
343 fx.Annotate(
344 func(myStringer myStringer) fmt.Stringer {
345 return &fromStringer{
346 name: myStringer.String(),
347 }
348 },
349 fx.From(new(*fromStringer)),
350 ),
351 ),

Callers

nothing calls this directly

Calls 12

ProvideFunction · 0.92
AnnotateFunction · 0.92
FromFunction · 0.92
ParamTagsFunction · 0.92
WithLoggerFunction · 0.92
NewTestLoggerFunction · 0.92
InvokeFunction · 0.92
NewForTestFunction · 0.85
RunMethod · 0.80
StringMethod · 0.65
ErrMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected