1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-11 11:29:52 +08:00

commands: Added tests for Command.Register

This commit is contained in:
Matt Bell
2014-10-09 13:39:34 -07:00
committed by Juan Batiz-Benet
parent 5b18844c06
commit e593c180fe

@ -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)")
}
}