forked from dfuse-io/dfuse-eosio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
blevequery_test.go
87 lines (78 loc) · 2.5 KB
/
blevequery_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 (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"testing"
"github.com/streamingfast/derr"
"github.com/streamingfast/search"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opencensus.io/trace"
"google.golang.org/grpc/codes"
)
func Test_validateQueryFields(t *testing.T) {
tests := []struct {
in string
expectedError error
}{
{
"account:eoscanadacom",
nil,
},
{
"unknow:eoscanadacom",
derr.Status(codes.InvalidArgument, "The following fields you are trying to search are not currently indexed: 'unknow'. Contact our support team for more."),
},
{
"unknow:eoscanadacom second:test",
derr.Status(codes.InvalidArgument, "The following fields you are trying to search are not currently indexed: 'second', 'unknow'. Contact our support team for more."),
},
{
"unknow:eoscanadacom account:value second:test",
derr.Status(codes.InvalidArgument, "The following fields you are trying to search are not currently indexed: 'second', 'unknow'. Contact our support team for more."),
},
{
"data.from:eoscanadacom data.nested:value account:test",
derr.Status(codes.InvalidArgument, "The following fields you are trying to search are not currently indexed: 'data.nested'. Contact our support team for more."),
},
{
"data.from:eoscanadacom data.nested.deep:value account:test",
derr.Status(codes.InvalidArgument, "The following fields you are trying to search are not currently indexed: 'data.nested.deep'. Contact our support team for more."),
},
{
"data.from.something:value data.auth.keys.key:value",
nil,
},
{
"event.field1:value event.field2.nested:value",
nil,
},
{
"data.from:eoscanadacom data.:value account:test",
derr.Status(codes.InvalidArgument, "The following fields you are trying to search are not currently indexed: 'data.'. Contact our support team for more."),
},
}
for idx, test := range tests {
t.Run(fmt.Sprintf("index %d", idx+1), func(t *testing.T) {
_, err := search.NewParsedQuery(context.Background(), test.in)
if test.expectedError == nil {
assert.NoError(t, err)
} else {
assert.JSONEq(t, toJSONString(t, test.expectedError), toJSONString(t, err))
}
})
}
}
func toJSONString(t *testing.T, v interface{}) string {
t.Helper()
out, err := json.Marshal(v)
require.NoError(t, err)
return string(out)
}
func fixedTraceID(hexInput string) (out trace.TraceID) {
rawTraceID, _ := hex.DecodeString(hexInput)
copy(out[:], rawTraceID)
return
}