Merge pull request #1243 from crosbymichael/reg-diff-urls
Panic when registering the same type but diff urls
This commit is contained in:
commit
f5bd8bbba3
@ -22,13 +22,19 @@ var (
|
|||||||
|
|
||||||
// Register a type with the base url of the type
|
// Register a type with the base url of the type
|
||||||
func Register(v interface{}, args ...string) {
|
func Register(v interface{}, args ...string) {
|
||||||
t := tryDereference(v)
|
var (
|
||||||
|
t = tryDereference(v)
|
||||||
|
p = path.Join(append([]string{Prefix}, args...)...)
|
||||||
|
)
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
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
|
return
|
||||||
}
|
}
|
||||||
registry[t] = path.Join(append([]string{Prefix}, args...)...)
|
registry[t] = p
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeURL returns the type url for a registred type
|
// 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) {
|
func BenchmarkMarshalEvent(b *testing.B) {
|
||||||
ev := &eventsapi.TaskStart{}
|
ev := &eventsapi.TaskStart{}
|
||||||
expected, err := MarshalAny(ev)
|
expected, err := MarshalAny(ev)
|
||||||
|
Loading…
Reference in New Issue
Block a user