@@ -243,19 +243,19 @@ func TestInvokeByTags(t *testing.T) {
243
243
ProvideValue (i , & eagerTest {foobar : "foobar" })
244
244
245
245
// no dependencies
246
- err := invokeByTags (i , reflect .ValueOf (& eagerTest {}))
246
+ err := invokeByTags (i , "*myStruct" , reflect .ValueOf (& eagerTest {}))
247
247
is .Nil (err )
248
248
249
249
// not pointer
250
- err = invokeByTags (i , reflect .ValueOf (eagerTest {}))
250
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (eagerTest {}))
251
251
is .Equal ("DI: not a pointer" , err .Error ())
252
252
253
253
// exported field - generic type
254
254
type hasExportedEagerTestDependency struct {
255
255
EagerTest * eagerTest `do:""`
256
256
}
257
257
test1 := hasExportedEagerTestDependency {}
258
- err = invokeByTags (i , reflect .ValueOf (& test1 ))
258
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (& test1 ))
259
259
is .Nil (err )
260
260
is .Equal ("foobar" , test1 .EagerTest .foobar )
261
261
@@ -264,7 +264,7 @@ func TestInvokeByTags(t *testing.T) {
264
264
eagerTest * eagerTest `do:""`
265
265
}
266
266
test2 := hasNonExportedEagerTestDependency {}
267
- err = invokeByTags (i , reflect .ValueOf (& test2 ))
267
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (& test2 ))
268
268
is .Nil (err )
269
269
is .Equal ("foobar" , test2 .eagerTest .foobar )
270
270
@@ -273,15 +273,15 @@ func TestInvokeByTags(t *testing.T) {
273
273
eagerTest * hasNonExportedEagerTestDependency `do:""` //nolint:unused
274
274
}
275
275
test3 := dependencyNotFound {}
276
- err = invokeByTags (i , reflect .ValueOf (& test3 ))
276
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (& test3 ))
277
277
is .Equal (serviceNotFound (i , []string {inferServiceName [* hasNonExportedEagerTestDependency ]()}).Error (), err .Error ())
278
278
279
279
// use tag
280
280
type namedDependency struct {
281
281
eagerTest * eagerTest `do:"int"` //nolint:unused
282
282
}
283
283
test4 := namedDependency {}
284
- err = invokeByTags (i , reflect .ValueOf (& test4 ))
284
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (& test4 ))
285
285
is .Equal (serviceNotFound (i , []string {inferServiceName [int ]()}).Error (), err .Error ())
286
286
287
287
// named service
@@ -290,7 +290,7 @@ func TestInvokeByTags(t *testing.T) {
290
290
EagerTest int `do:"foobar"`
291
291
}
292
292
test5 := namedService {}
293
- err = invokeByTags (i , reflect .ValueOf (& test5 ))
293
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (& test5 ))
294
294
is .Nil (err )
295
295
is .Equal (42 , test5 .EagerTest )
296
296
@@ -299,8 +299,8 @@ func TestInvokeByTags(t *testing.T) {
299
299
EagerTest * int `do:"*github.com/samber/do/v2.eagerTest"`
300
300
}
301
301
test6 := namedDependencyButTypeMismatch {}
302
- err = invokeByTags (i , reflect .ValueOf (& test6 ))
303
- is .Equal ("DI: field ' EagerTest' is not assignable to service *github.com/samber/do/v2.eagerTest" , err .Error ())
302
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (& test6 ))
303
+ is .Equal ("DI: field `*myStruct. EagerTest` is not assignable to service *github.com/samber/do/v2.eagerTest" , err .Error ())
304
304
305
305
// use a custom tag
306
306
i = NewWithOpts (& InjectorOpts {StructTagKey : "hello" })
@@ -309,7 +309,7 @@ func TestInvokeByTags(t *testing.T) {
309
309
EagerTest int `hello:"foobar"`
310
310
}
311
311
test7 := namedServiceWithCustomTag {}
312
- err = invokeByTags (i , reflect .ValueOf (& test7 ))
312
+ err = invokeByTags (i , "*myStruct" , reflect .ValueOf (& test7 ))
313
313
is .Nil (err )
314
314
is .Equal (42 , test7 .EagerTest )
315
315
}
0 commit comments