mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-19 01:39:35 +08:00
commands: Added tests for Command.Register
This commit is contained in:

committed by
Juan Batiz-Benet

parent
5b18844c06
commit
e593c180fe
@ -58,3 +58,58 @@ func TestOptionValidation(t *testing.T) {
|
|||||||
t.Error("Should have passed")
|
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)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user