summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2015-07-10 21:56:08 +0000
committerBrian Cully <bjc@kublai.com>2015-07-10 21:56:14 +0000
commit6d7a72918b163c155858a152ee65fdac75ac381d (patch)
tree1bbb3482989b6f4c2f3a2032ebfa9f61ae0da487
parent21a44a952f0272d094d8dc01163065da5a6ce12e (diff)
downloadgoctl-6d7a72918b163c155858a152ee65fdac75ac381d.tar.gz
goctl-6d7a72918b163c155858a152ee65fdac75ac381d.zip
Make AddHandlers() variadic, remove AddHandler().HEADmaster
-rw-r--r--goctl.go6
-rw-r--r--goctl_test.go36
2 files changed, 6 insertions, 36 deletions
diff --git a/goctl.go b/goctl.go
index 6379cd9..a108feb 100644
--- a/goctl.go
+++ b/goctl.go
@@ -89,11 +89,7 @@ func (gc *Goctl) Stop() {
}
}
-func (gc *Goctl) AddHandler(h Handler) error {
- return gc.AddHandlers([]Handler{h})
-}
-
-func (gc *Goctl) AddHandlers(handlers []Handler) error {
+func (gc *Goctl) AddHandlers(handlers ...Handler) error {
for _, h := range handlers {
if gc.handlers[h.Name()] != nil {
return HandlerExists
diff --git a/goctl_test.go b/goctl_test.go
index 1ab0238..2c011b1 100644
--- a/goctl_test.go
+++ b/goctl_test.go
@@ -95,37 +95,11 @@ func TestSimulCommands(t *testing.T) {
}
}
-func TestAddHandler(t *testing.T) {
- gc := start(t)
- defer gc.Stop()
-
- gc.AddHandler(makeHandler("foo", func(innerGC *Goctl, args []string) string {
- if innerGC != gc {
- t.Errorf("Goctl object not passed into handler properly (got: %p, want: %p).", innerGC, gc)
- }
- if !reflect.DeepEqual(args, []string{"bar", "baz"}) {
- t.Errorf("Got %v, expected ['bar', 'baz']", args)
- }
- return "bar baz"
- }))
-
- c := dial(t)
- defer c.Close()
-
- Write(c, []byte("foo\u0000bar\u0000baz"))
-
- if buf, err := Read(c); err != nil {
- t.Errorf("Couldn't read from connection: %s.", err)
- } else if string(buf) != "bar baz" {
- t.Errorf("Got: %s, expected 'bar baz'")
- }
-}
-
func TestAddHandlers(t *testing.T) {
gc := start(t)
defer gc.Stop()
- gc.AddHandlers([]Handler{
+ gc.AddHandlers(
makeHandler("foo", func(_ *Goctl, args []string) string {
if !reflect.DeepEqual(args, []string{"bar", "baz"}) {
t.Errorf("Got %v, expected ['bar', 'baz']", args)
@@ -138,7 +112,7 @@ func TestAddHandlers(t *testing.T) {
}
return "wauug"
}),
- })
+ )
c := dial(t)
defer c.Close()
@@ -163,16 +137,16 @@ func TestCannotOverrideExtantHandlers(t *testing.T) {
gc := start(t)
defer gc.Stop()
- err := gc.AddHandler(makeHandler("ping", func(_ *Goctl, args []string) string {
+ err := gc.AddHandlers(makeHandler("ping", func(_ *Goctl, args []string) string {
return "gnip"
}))
if err != HandlerExists {
t.Error("Was able to override built-in ping handler.")
}
- err = gc.AddHandlers([]Handler{
+ err = gc.AddHandlers(
makeHandler("foo", func(_ *Goctl, args []string) string { return "foo" }),
makeHandler("foo", func(_ *Goctl, args []string) string { return "foo" }),
- })
+ )
if err != HandlerExists {
t.Error("Was able to assign two handlers for 'foo'.")
}