@cryptotaxi247 / kubo / commits / e593c180f

commands: Added tests for Command.Register

Matt Bell committed Oct 9, 2014 at 13:39 UTC e593c180fee8ddefac8520f31cd8429d308e1dd9
1 file changed +55
commands/command_test.go
+55
@@ -58,3 +58,58 @@ func TestOptionValidation(t *testing.T) {
58 t.Error("Should have passed")
59 }
60 }
61 +
62 +func TestRegistration(t *testing.T) {
63 + cmds := []*Command{
64 + &Command{
65 + Options: []Option{
66 + Option{ []string{ "beep" }, Int },
67 + },
68 + f: func(req *Request) (interface{}, error) {
69 + return nil, nil
70 + },
71 + },
72 +
73 + &Command{
74 + Options: []Option{
75 + Option{ []string{ "boop" }, Int },
76 + },
77 + f: func(req *Request) (interface{}, error) {
78 + return nil, nil
79 + },
80 + },
81 +
82 + &Command{
83 + Options: []Option{
84 + Option{ []string{ "boop" }, String },
85 + },
86 + f: func(req *Request) (interface{}, error) {
87 + return nil, nil
88 + },
89 + },
90 +
91 + &Command{
92 + Options: []Option{
93 + Option{ []string{ "bop" }, String },
94 + },
95 + f: func(req *Request) (interface{}, error) {
96 + return nil, nil
97 + },
98 + },
99 + }
100 +
101 + err := cmds[0].Register("foo", cmds[1])
102 + if err != nil {
103 + t.Error("Should have passed")
104 + }
105 +
106 + err = cmds[0].Register("bar", cmds[2])
107 + if err == nil {
108 + t.Error("Should have failed (option name collision)")
109 + }
110 +
111 + err = cmds[0].Register("foo", cmds[3])
112 + if err == nil {
113 + t.Error("Should have failed (subcommand name collision)")
114 + }
115 +}