From e593c180fee8ddefac8520f31cd8429d308e1dd9 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Thu, 9 Oct 2014 13:39:34 -0700 Subject: [PATCH] commands: Added tests for Command.Register --- commands/command_test.go | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/commands/command_test.go b/commands/command_test.go index f08e37560..d0ce34147 100644 --- a/commands/command_test.go +++ b/commands/command_test.go @@ -58,3 +58,58 @@ func TestOptionValidation(t *testing.T) { t.Error("Should have passed") } } + +func TestRegistration(t *testing.T) { + cmds := []*Command{ + &Command{ + Options: []Option{ + Option{ []string{ "beep" }, Int }, + }, + f: func(req *Request) (interface{}, error) { + return nil, nil + }, + }, + + &Command{ + Options: []Option{ + Option{ []string{ "boop" }, Int }, + }, + f: func(req *Request) (interface{}, error) { + return nil, nil + }, + }, + + &Command{ + Options: []Option{ + Option{ []string{ "boop" }, String }, + }, + f: func(req *Request) (interface{}, error) { + return nil, nil + }, + }, + + &Command{ + Options: []Option{ + Option{ []string{ "bop" }, String }, + }, + f: func(req *Request) (interface{}, error) { + return nil, nil + }, + }, + } + + err := cmds[0].Register("foo", cmds[1]) + if err != nil { + t.Error("Should have passed") + } + + err = cmds[0].Register("bar", cmds[2]) + if err == nil { + t.Error("Should have failed (option name collision)") + } + + err = cmds[0].Register("foo", cmds[3]) + if err == nil { + t.Error("Should have failed (subcommand name collision)") + } +}