@cryptotaxi247 / kubo / commits / 8061117e0

core/commands: add TestROCommands

License: MIT Signed-off-by: keks <keks@cryptoscope.co>

keks committed Dec 20, 2017 at 17:41 UTC 8061117e0c95293285e6956fa9533d53d2c6f02f
1 file changed +51
core/commands/commands_test.go
+51
@@ -15,6 +15,57 @@ func collectPaths(prefix string, cmd *cmds.Command, out map[string]struct{}) {
15 }
16 }
17
18 +func TestROCommands(t *testing.T) {
19 + list := []string{
20 + "/block",
21 + "/block/get",
22 + "/block/stat",
23 + "/cat",
24 + "/commands",
25 + "/dag",
26 + "/dag/get",
27 + "/dag/resolve",
28 + "/dns",
29 + "/get",
30 + "/ls",
31 + "/name",
32 + "/name/resolve",
33 + "/object",
34 + "/object/data",
35 + "/object/get",
36 + "/object/links",
37 + "/object/stat",
38 + "/refs",
39 + "/resolve",
40 + "/version",
41 + }
42 +
43 + cmdSet := make(map[string]struct{})
44 + collectPaths("", RootRO, cmdSet)
45 +
46 + for _, path := range list {
47 + if _, ok := cmdSet[path]; !ok {
48 + t.Errorf("%q not in result", path)
49 + } else {
50 + delete(cmdSet, path)
51 + }
52 + }
53 +
54 + for path := range cmdSet {
55 + t.Errorf("%q in result but shouldn't be", path)
56 + }
57 +
58 + for _, path := range list {
59 + path = path[1:] // remove leading slash
60 + split := strings.Split(path, "/")
61 + sub, err := RootRO.Get(split)
62 + if err != nil {
63 + t.Errorf("error getting subcommand %q: %v", path, err)
64 + } else if sub == nil {
65 + t.Errorf("subcommand %q is nil even though there was no error", path)
66 + }
67 + }
68 +}
69 func TestCommands(t *testing.T) {
70 list := []string{
71 "/add",