Panic when registering the same type but diff urls
Panic on typeurl registration when you register the same type but different urls for that type. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
c52523c4d3
commit
a3769f887b
@ -22,13 +22,19 @@ var (
|
||||
|
||||
// Register a type with the base url of the type
|
||||
func Register(v interface{}, args ...string) {
|
||||
t := tryDereference(v)
|
||||
var (
|
||||
t = tryDereference(v)
|
||||
p = path.Join(append([]string{Prefix}, args...)...)
|
||||
)
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if _, ok := registry[t]; ok {
|
||||
if et, ok := registry[t]; ok {
|
||||
if et != p {
|
||||
panic(errors.Errorf("type registred with alternate path %q != %q", et, p))
|
||||
}
|
||||
return
|
||||
}
|
||||
registry[t] = path.Join(append([]string{Prefix}, args...)...)
|
||||
registry[t] = p
|
||||
}
|
||||
|
||||
// TypeURL returns the type url for a registred type
|
||||
|
@ -130,6 +130,17 @@ func TestMarshalEvent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterDiffUrls(t *testing.T) {
|
||||
clear()
|
||||
defer func() {
|
||||
if err := recover(); err == nil {
|
||||
t.Error("registering the same type with different urls should panic")
|
||||
}
|
||||
}()
|
||||
Register(&test{}, "test")
|
||||
Register(&test{}, "test", "two")
|
||||
}
|
||||
|
||||
func BenchmarkMarshalEvent(b *testing.B) {
|
||||
ev := &eventsapi.TaskStart{}
|
||||
expected, err := MarshalAny(ev)
|
||||
|
Loading…
Reference in New Issue
Block a user