-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_keys_test.go
52 lines (46 loc) · 1.21 KB
/
parse_keys_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package nvault_test
import (
"testing"
"github.com/reproio/nvault"
)
func TestParseKeys(t *testing.T) {
tests := []struct {
clikey string
expected []nvault.Path
err string
}{
{
"$.test.[0]./test/,$./test/.[0].test",
[]nvault.Path{
{
nvault.PathFragment{Type: "string", Fragment: "$"},
nvault.PathFragment{Type: "string", Fragment: "test"},
nvault.PathFragment{Type: "number", Fragment: "0"},
nvault.PathFragment{Type: "regexp", Fragment: "test"},
},
{
nvault.PathFragment{Type: "string", Fragment: "$"},
nvault.PathFragment{Type: "regexp", Fragment: "test"},
nvault.PathFragment{Type: "number", Fragment: "0"},
nvault.PathFragment{Type: "string", Fragment: "test"},
},
},
"",
},
{`"has not root"`, nil, "`$` must be at first"},
}
for _, test := range tests {
paths, err := nvault.ParseKeys(test.clikey)
if test.err != "" {
if err == nil {
t.Errorf("unexpected: clikey %v returns %v expected %v", test.clikey, err, test.err)
}
continue
}
for i, expected := range test.expected {
if !expected.Equal(paths[i]) {
t.Errorf("unexpected: clikey %v returns %v expected %v", test.clikey, paths[i], expected)
}
}
}
}