github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/querytracker/snhasher_test.go (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package querytracker 18 19 import ( 20 "testing" 21 22 "github.com/siglens/siglens/pkg/segment/utils" 23 "github.com/stretchr/testify/assert" 24 25 . "github.com/siglens/siglens/pkg/segment/structs" 26 ) 27 28 func Test_HashSearchNode(t *testing.T) { 29 30 qVal, err := utils.CreateDtypeEnclosure("iOS", 0) 31 assert.Nil(t, err) 32 33 sNode := &SearchNode{ 34 AndSearchConditions: &SearchCondition{ 35 SearchQueries: []*SearchQuery{ 36 { 37 ExpressionFilter: &SearchExpression{ 38 LeftSearchInput: &SearchExpressionInput{ColumnName: "os"}, 39 FilterOp: utils.Equals, 40 RightSearchInput: &SearchExpressionInput{ColumnValue: qVal}, 41 }, 42 SearchType: SimpleExpression, 43 }, 44 }, 45 }, 46 NodeType: ColumnValueQuery, 47 } 48 49 hid1 := GetHashForQuery(sNode) 50 expected := "11481340929163441556" // pre-computed hashid to compare against for above query 51 assert.Equal(t, expected, hid1, "hid1=%v, not equal to expected=%v", hid1, expected) 52 53 hid2 := GetHashForQuery(sNode) 54 assert.Equal(t, hid1, hid2, "hid2=%v, not equal to expected=%v", hid2, hid1) 55 56 for i := 0; i < 10; i++ { 57 newId := GetHashForQuery(sNode) 58 assert.Equal(t, expected, newId, "hid2=%v, not equal to expected=%v", newId, expected) 59 } 60 }