Merge pull request #1243 from crosbymichael/reg-diff-urls

Panic when registering the same type but diff urls
This commit is contained in:
Stephen Day 2017-07-24 14:58:36 -07:00 committed by GitHub
commit f5bd8bbba3
2 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -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)