summaryrefslogtreecommitdiffstats
path: root/goctl_test.go
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2015-07-10 18:00:24 +0000
committerBrian Cully <bjc@kublai.com>2015-07-10 18:07:57 +0000
commit9408742ed1a7eef568e2bf0d8e1aba390ae4d80b (patch)
tree380f45d9a542b1d492911457aedb1c6b632127cb /goctl_test.go
parentab72c2f0b56ce9929b46af1df09d30e2a7552b30 (diff)
downloadgoctl-9408742ed1a7eef568e2bf0d8e1aba390ae4d80b.tar.gz
goctl-9408742ed1a7eef568e2bf0d8e1aba390ae4d80b.zip
Move builtin commands into objects handlers on creation.
This simplifies lookup. Still prevents overriding of command handlers.
Diffstat (limited to 'goctl_test.go')
-rw-r--r--goctl_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/goctl_test.go b/goctl_test.go
index d33fe32..a1e4711 100644
--- a/goctl_test.go
+++ b/goctl_test.go
@@ -154,6 +154,25 @@ func TestAddHandlers(t *testing.T) {
}
}
+func TestCannotOverrideExtantHandlers(t *testing.T) {
+ gc := start(t)
+ defer gc.Stop()
+
+ err := gc.AddHandler("ping", func(args []string) string {
+ return "gnip"
+ })
+ if err != HandlerExists {
+ t.Error("Was able to override built-in ping handler.")
+ }
+ err = gc.AddHandlers([]*Handler{
+ {"foo", func(args []string) string { return "foo" }},
+ {"foo", func(args []string) string { return "foo" }},
+ })
+ if err != HandlerExists {
+ t.Error("Was able to assign two handlers for 'foo'.")
+ }
+}
+
func BenchmarkStartStop(b *testing.B) {
gc := NewGoctl(sockpath)
for i := 0; i < b.N; i++ {