From 15b1e4d8cea714493b2f4d10fff31982441b980e Mon Sep 17 00:00:00 2001 From: vlamug Date: Fri, 11 Jan 2019 19:14:49 +0400 Subject: [PATCH] The test for checking incorrect traceID. --- plugin/storage/es/spanstore/reader_test.go | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugin/storage/es/spanstore/reader_test.go b/plugin/storage/es/spanstore/reader_test.go index 227f25146e7c..aecc71e433ba 100644 --- a/plugin/storage/es/spanstore/reader_test.go +++ b/plugin/storage/es/spanstore/reader_test.go @@ -784,6 +784,29 @@ func TestSpanReader_FindTraceIDsReadTraceIDsFailure(t *testing.T) { }) } +func TestSpanReader_FindTraceIDsIncorrectTraceIDFailure(t *testing.T) { + goodAggregations := make(map[string]*json.RawMessage) + rawMessage := []byte(`{"buckets": [{"key": "dfddslsfdsfdsdscc","doc_count": 16},{"key": "2","doc_count": 16}]}`) + goodAggregations[traceIDAggregation] = (*json.RawMessage)(&rawMessage) + + withSpanReader(func(r *spanReaderTest) { + mockSearchService(r).Return(&elastic.SearchResult{Aggregations: elastic.Aggregations(goodAggregations)}, nil) + + traceIDsQuery := &spanstore.TraceQueryParameters{ + ServiceName: serviceName, + Tags: map[string]string{ + "hello": "world", + }, + StartTimeMin: time.Now().Add(-1 * time.Hour), + StartTimeMax: time.Now(), + } + + traceIDs, err := r.reader.FindTraceIDs(context.Background(), traceIDsQuery) + require.EqualError(t, err, "strconv.ParseUint: parsing \"fddslsfdsfdsdscc\": invalid syntax") + assert.Len(t, traceIDs, 0) + }) +} + func mockMultiSearchService(r *spanReaderTest) *mock.Call { multiSearchService := &mocks.MultiSearchService{} multiSearchService.On("Add", mock.Anything, mock.Anything, mock.Anything).Return(multiSearchService)