di/registry/registry_test.go

35 lines
875 B
Go
Raw Normal View History

2017-12-05 13:28:42 +00:00
package registry
import (
"reflect"
"testing"
cda "git.loafle.net/commons_go/di/annotation"
)
func TestRegisterType(t *testing.T) {
2017-12-06 00:48:03 +00:00
RegisterType(reflect.TypeOf((*TestStruct1)(nil)), &cda.ComponentAnnotation{})
RegisterType(reflect.TypeOf((*TestStruct2)(nil)), &cda.ComponentAnnotation{
2017-12-06 06:07:44 +00:00
Name: "test1",
2017-12-05 13:31:19 +00:00
})
2017-12-06 00:48:03 +00:00
RegisterType(reflect.TypeOf((*TestStruct3)(nil)), &cda.ComponentAnnotation{
2017-12-06 06:07:44 +00:00
Name: "test2",
2017-12-05 13:31:19 +00:00
})
2017-12-05 13:28:42 +00:00
}
2017-12-06 00:48:03 +00:00
type TestStruct1 struct {
Name1 string `annotation:"@Inject"`
Name2 string `annotation:"@Inject()"`
2017-12-06 06:07:44 +00:00
Name3 string `annotation:"@Inject(name=test1)"`
2017-12-06 00:48:03 +00:00
}
type TestStruct2 struct {
Name1 string `annotation:"@Inject"`
Name2 string `annotation:"@Inject()"`
2017-12-06 06:07:44 +00:00
Name3 string `annotation:"@Inject(name=test2)"`
2017-12-06 00:48:03 +00:00
}
type TestStruct3 struct {
2017-12-05 13:28:42 +00:00
Name1 string `annotation:"@Inject"`
Name2 string `annotation:"@Inject()"`
2017-12-06 06:07:44 +00:00
Name3 string `annotation:"@Inject(name=test3)"`
2017-12-05 13:28:42 +00:00
}