-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_test.go
153 lines (126 loc) · 4.42 KB
/
new_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2020 Couchbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ice
import (
"path/filepath"
"testing"
segment "github.com/blugelabs/bluge_segment_api"
)
func TestBuild(t *testing.T) {
path, cleanup := setupTestDir(t)
defer cleanup()
sb, err := buildTestSegment()
if err != nil {
t.Fatal(err)
}
segPath := filepath.Join(path, "segment.ice")
err = persistToFile(sb, segPath)
if err != nil {
t.Fatal(err)
}
}
func buildTestSegment() (*Segment, error) {
doc := &FakeDocument{
NewFakeField("_id", "a", true, false, false),
NewFakeField("name", "wow", true, true, false),
NewFakeField("desc", "some thing", true, true, false),
NewFakeField("tag", "cold", true, true, false),
NewFakeField("tag", "dark", true, true, false),
}
doc.FakeComposite("_all", []string{"_id"})
results := []segment.Document{
doc,
}
seg, _, err := newWithChunkMode(results, encodeNorm, defaultChunkMode)
return seg.(*Segment), err
}
func buildTestSegmentMulti() (*Segment, error) {
results := buildTestAnalysisResultsMulti()
seg, _, err := newWithChunkMode(results, encodeNorm, defaultChunkMode)
return seg.(*Segment), err
}
func buildTestSegmentMultiWithChunkFactor(chunkFactor uint32) (*Segment, error) {
results := buildTestAnalysisResultsMulti()
seg, _, err := newWithChunkMode(results, encodeNorm, chunkFactor)
return seg.(*Segment), err
}
func buildTestSegmentMultiWithDifferentFields(includeDocA, includeDocB bool) (*Segment, error) {
results := buildTestAnalysisResultsMultiWithDifferentFields(includeDocA, includeDocB)
seg, _, err := newWithChunkMode(results, encodeNorm, defaultChunkMode)
return seg.(*Segment), err
}
func buildTestAnalysisResultsMulti() []segment.Document {
doc := &FakeDocument{
NewFakeField("_id", "a", true, false, false),
NewFakeField("name", "wow", true, true, false),
NewFakeField("desc", "some thing", true, true, false),
NewFakeField("tag", "dark", true, true, false),
}
doc.FakeComposite("_all", []string{"_id"})
doc2 := &FakeDocument{
NewFakeField("_id", "b", true, false, false),
NewFakeField("name", "who", true, true, false),
NewFakeField("desc", "some thing", true, true, false),
NewFakeField("tag", "cold", true, true, false),
NewFakeField("tag", "dark", true, true, false),
}
doc2.FakeComposite("_all", []string{"_id"})
results := []segment.Document{
doc, doc2,
}
return results
}
func buildTestAnalysisResultsMultiWithDifferentFields(includeDocA, includeDocB bool) []segment.Document {
var results []segment.Document
if includeDocA {
doc := &FakeDocument{
NewFakeField("_id", "a", false, false, false),
NewFakeField("name", "ABC", false, false, true),
NewFakeField("dept", "ABC dept", false, false, true),
NewFakeField("manages.id", "XYZ", false, false, true),
NewFakeField("manages.count", "1", false, false, true),
}
doc.FakeComposite("_all", []string{"_id"})
results = append(results, doc)
}
if includeDocB {
doc := &FakeDocument{
NewFakeField("_id", "b", true, false, false),
NewFakeField("name", "XYZ", false, false, true),
NewFakeField("dept", "ABC dept", false, false, true),
NewFakeField("reportsTo.id", "ABC", false, false, true),
}
doc.FakeComposite("_all", []string{"_id"})
results = append(results, doc)
}
return results
}
func buildTestSegmentWithDefaultFieldMapping(chunkFactor uint32) (
*Segment, []string, error) {
doc := &FakeDocument{
NewFakeField("_id", "a", true, false, false),
NewFakeField("name", "wow", false, false, true),
NewFakeField("desc", "some thing", false, false, true),
NewFakeField("tag", "cold", false, false, true),
NewFakeField("number", string([]byte{0xff})+" "+string([]byte{'\\'}), false, false, true),
}
doc.FakeComposite("_all", []string{"_id"})
var fields []string
fields = append(fields, "_id", "name", "desc", "tag")
results := []segment.Document{
doc,
}
sb, _, err := newWithChunkMode(results, encodeNorm, chunkFactor)
return sb.(*Segment), fields, err
}