forked from RediSearch/redisearch-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_test.go
41 lines (39 loc) · 1.96 KB
/
index_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
package redisearch
import (
"github.com/gomodule/redigo/redis"
"reflect"
"testing"
)
func TestIndexDefinition_Serialize(t *testing.T) {
type fields struct {
Definition *IndexDefinition
}
type args struct {
args redis.Args
}
tests := []struct {
name string
fields fields
args args
want redis.Args
}{
{"default", fields{NewIndexDefinition()}, args{redis.Args{}}, redis.Args{"ON", "HASH"}},
{"default", fields{NewIndexDefinition().SetIndexOn(JSON)}, args{redis.Args{}}, redis.Args{"ON", "JSON"}},
{"default+async", fields{NewIndexDefinition().SetAsync(true)}, args{redis.Args{}}, redis.Args{"ON", "HASH", "ASYNC"}},
{"default+score", fields{NewIndexDefinition().SetScore(0.75)}, args{redis.Args{}}, redis.Args{"ON", "HASH", "SCORE", 0.75}},
{"default+score_field", fields{NewIndexDefinition().SetScoreField("myscore")}, args{redis.Args{}}, redis.Args{"ON", "HASH", "SCORE_FIELD", "myscore"}},
{"default+language", fields{NewIndexDefinition().SetLanguage("portuguese")}, args{redis.Args{}}, redis.Args{"ON", "HASH", "LANGUAGE", "portuguese"}},
{"default+language_field", fields{NewIndexDefinition().SetLanguageField("mylanguage")}, args{redis.Args{}}, redis.Args{"ON", "HASH", "LANGUAGE_FIELD", "mylanguage"}},
{"default+prefix", fields{NewIndexDefinition().AddPrefix("products:*")}, args{redis.Args{}}, redis.Args{"ON", "HASH", "PREFIX", 1, "products:*"}},
{"default+payload_field", fields{NewIndexDefinition().SetPayloadField("products_description")}, args{redis.Args{}}, redis.Args{"ON", "HASH", "PAYLOAD_FIELD", "products_description"}},
{"default+filter", fields{NewIndexDefinition().SetFilterExpression("@score:[0 50]")}, args{redis.Args{}}, redis.Args{"ON", "HASH", "FILTER", "@score:[0 50]"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defintion := tt.fields.Definition
if got := defintion.Serialize(tt.args.args); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Serialize() = %v, want %v", got, tt.want)
}
})
}
}