summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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'.")
}