-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathfind_test.go
87 lines (81 loc) · 1.34 KB
/
find_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package search
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSearchOnList(t *testing.T) {
entities := []named{
namedStruct{
ID: "1",
Name: "entity one",
},
namedStruct{
ID: "2",
Name: "entity two",
},
namedStruct{
ID: "3",
Name: "entity three",
},
namedStruct{
ID: "4",
Name: "more complex name",
},
namedStruct{
ID: "id",
Name: "by id",
},
namedStruct{
ID: "bra",
Name: "with [bracket]",
},
}
tts := []struct {
name string
search string
entities []named
result string
}{
{
name: "one term",
search: "two",
entities: entities,
result: "2",
},
{
name: "two terms",
search: "complex name",
entities: entities,
result: "4",
},
{
name: "sections of the name",
search: "mo nam",
entities: entities,
result: "4",
},
{
name: "with brackets",
search: "[bracket]",
entities: entities,
result: "bra",
},
{
name: "using id",
search: "by id",
entities: entities,
result: "id",
},
}
for i := range tts {
tt := tts[i]
t.Run(tt.name, func(t *testing.T) {
id, err := findByName(tt.search, "element", func() ([]named, error) {
return tt.entities, nil
})
if assert.NoError(t, err) {
assert.Equal(t, tt.result, id)
}
})
}
}