Skip to content

Commit b7c849a

Browse files
test: add negative test case
1 parent 34392fa commit b7c849a

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

finder/split.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,10 @@ func (splitFinder *SplitIndexFinder) whereFilter(queries []string, from, until i
218218
}
219219

220220
if queryWithWildcardIdx >= 0 {
221-
splitFinder.useReverse = NewIndex(
222-
splitFinder.url,
223-
splitFinder.table,
224-
splitFinder.dailyEnabled,
225-
splitFinder.reverse,
226-
splitFinder.confReverses,
227-
splitFinder.opts,
228-
splitFinder.useCache,
229-
).(*IndexFinder).useReverse(queries[queryWithWildcardIdx])
221+
splitFinder.useReverse = (&IndexFinder{
222+
confReverses: splitFinder.confReverses,
223+
confReverse: config.IndexReverse[splitFinder.reverse],
224+
}).useReverse(queries[queryWithWildcardIdx])
230225
} else {
231226
splitFinder.useReverse = false
232227
}

finder/split_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package finder
22

33
import (
44
"fmt"
5+
"net/http"
56
"testing"
67
"time"
78

89
"github.com/lomik/graphite-clickhouse/config"
910
"github.com/lomik/graphite-clickhouse/helper/clickhouse"
1011
"github.com/lomik/graphite-clickhouse/helper/date"
12+
"github.com/lomik/graphite-clickhouse/helper/errs"
1113
"github.com/stretchr/testify/assert"
1214
)
1315

@@ -286,7 +288,16 @@ func TestSplitIndexFinder_whereFilter(t *testing.T) {
286288
givenUntil: someUntil,
287289
expectedWhereStr: "((((Path LIKE 'count.metric.%' AND match(Path, '^count[.]metric[.]([^.]*?)first[.]help[.]?$')) OR (Path LIKE 'count.metric.th%' AND match(Path, '^count[.]metric[.]th([^.]*?)rd[.]help[.]?$'))) OR (Path IN ('count.metric.second.help','count.metric.second.help.','count.metric.forth.help','count.metric.forth.help.'))) AND (Level=10004)) AND (Date >='" +
288290
date.FromTimestampToDaysFormat(someFrom) + "' AND Date <= '" + date.UntilTimestampToDaysFormat(someUntil) + "')",
289-
expectedErr: nil,
291+
},
292+
{
293+
name: "queries do not satisfy wildcard min distance",
294+
givenQueries: []string{
295+
"*.first.metric.*",
296+
"*.second.metric.*",
297+
},
298+
wildcardMinDistance: 1,
299+
expectedWhereStr: "",
300+
expectedErr: errs.NewErrorWithCode("query has wildcards way too early at the start and at the end of it", http.StatusBadRequest),
290301
},
291302
}
292303

@@ -305,7 +316,9 @@ func TestSplitIndexFinder_whereFilter(t *testing.T) {
305316

306317
got, err := f.whereFilter(tc.givenQueries, tc.givenFrom, tc.givenUntil)
307318
assert.Equal(t, tc.expectedErr, err)
308-
assert.Equal(t, tc.expectedWhereStr, got.String())
319+
if err == nil {
320+
assert.Equal(t, tc.expectedWhereStr, got.String())
321+
}
309322
})
310323
}
311324
}

0 commit comments

Comments
 (0)