Add ability to register commands

This commit is contained in:
Derek Parker
2014-05-20 18:09:34 -05:00
parent 84f80fd149
commit 8f5190cbef
2 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,9 @@
package command
import "testing"
import (
"fmt"
"testing"
)
func TestCommandDefault(t *testing.T) {
var (
@ -17,3 +20,20 @@ func TestCommandDefault(t *testing.T) {
t.Fatal("wrong command output")
}
}
func TestCommandRegister(t *testing.T) {
cmds := Commands{make(map[string]cmdfunc)}
cmds.Register("foo", func() error { return fmt.Errorf("registered command") })
cmd := cmds.Find("foo")
err := cmd()
if err == nil {
t.Fatal("cmd was not found")
}
if err.Error() != "registered command" {
t.Fatal("wrong command output")
}
}