|
| 1 | +// Copyright (c) 2020 The Jaeger Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package shared |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "io" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | + "github.com/stretchr/testify/mock" |
| 24 | + |
| 25 | + "github.com/jaegertracing/jaeger/model" |
| 26 | + "github.com/jaegertracing/jaeger/proto-gen/storage_v1" |
| 27 | + "github.com/jaegertracing/jaeger/proto-gen/storage_v1/mocks" |
| 28 | + "github.com/jaegertracing/jaeger/storage/spanstore" |
| 29 | +) |
| 30 | + |
| 31 | +func TestArchiveWriter_WriteSpan(t *testing.T) { |
| 32 | + mockSpan := &model.Span{ |
| 33 | + TraceID: mockTraceID, |
| 34 | + SpanID: model.NewSpanID(1), |
| 35 | + Process: &model.Process{}, |
| 36 | + } |
| 37 | + |
| 38 | + archiveWriter := new(mocks.ArchiveSpanWriterPluginClient) |
| 39 | + archiveWriter.On("WriteArchiveSpan", mock.Anything, &storage_v1.WriteSpanRequest{Span: mockSpan}). |
| 40 | + Return(&storage_v1.WriteSpanResponse{}, nil) |
| 41 | + writer := &ArchiveWriter{archiveWriter} |
| 42 | + |
| 43 | + err := writer.WriteSpan(mockSpan) |
| 44 | + assert.NoError(t, err) |
| 45 | +} |
| 46 | + |
| 47 | +func TestArchiveReader_GetTrace(t *testing.T) { |
| 48 | + mockTraceID := model.NewTraceID(0, 123456) |
| 49 | + mockSpan := model.Span{ |
| 50 | + TraceID: mockTraceID, |
| 51 | + SpanID: model.NewSpanID(1), |
| 52 | + Process: &model.Process{}, |
| 53 | + } |
| 54 | + expected := &model.Trace{ |
| 55 | + Spans: []*model.Span{&mockSpan}, |
| 56 | + } |
| 57 | + |
| 58 | + traceClient := new(mocks.ArchiveSpanReaderPlugin_GetArchiveTraceClient) |
| 59 | + traceClient.On("Recv").Return(&storage_v1.SpansResponseChunk{ |
| 60 | + Spans: []model.Span{mockSpan}, |
| 61 | + }, nil).Once() |
| 62 | + traceClient.On("Recv").Return(nil, io.EOF) |
| 63 | + |
| 64 | + archiveReader := new(mocks.ArchiveSpanReaderPluginClient) |
| 65 | + archiveReader.On("GetArchiveTrace", mock.Anything, &storage_v1.GetTraceRequest{ |
| 66 | + TraceID: mockTraceID, |
| 67 | + }).Return(traceClient, nil) |
| 68 | + reader := &ArchiveReader{archiveReader} |
| 69 | + |
| 70 | + trace, err := reader.GetTrace(context.Background(), mockTraceID) |
| 71 | + assert.NoError(t, err) |
| 72 | + assert.Equal(t, expected, trace) |
| 73 | +} |
| 74 | + |
| 75 | +func TestArchiveReader_FindTraceIDs(t *testing.T) { |
| 76 | + assert.Panics(t, func() { |
| 77 | + reader := ArchiveReader{&mocks.ArchiveSpanReaderPluginClient{}} |
| 78 | + _, _ = reader.FindTraceIDs(context.Background(), nil) |
| 79 | + }) |
| 80 | +} |
| 81 | + |
| 82 | +func TestArchiveReader_FindTraces(t *testing.T) { |
| 83 | + assert.Panics(t, func() { |
| 84 | + reader := ArchiveReader{&mocks.ArchiveSpanReaderPluginClient{}} |
| 85 | + _, _ = reader.FindTraces(context.Background(), nil) |
| 86 | + }) |
| 87 | +} |
| 88 | + |
| 89 | +func TestArchiveReader_GetOperations(t *testing.T) { |
| 90 | + assert.Panics(t, func() { |
| 91 | + reader := ArchiveReader{&mocks.ArchiveSpanReaderPluginClient{}} |
| 92 | + _, _ = reader.GetOperations(context.Background(), spanstore.OperationQueryParameters{}) |
| 93 | + }) |
| 94 | +} |
| 95 | + |
| 96 | +func TestArchiveReader_GetServices(t *testing.T) { |
| 97 | + assert.Panics(t, func() { |
| 98 | + reader := ArchiveReader{&mocks.ArchiveSpanReaderPluginClient{}} |
| 99 | + _, _ = reader.GetServices(context.Background()) |
| 100 | + }) |
| 101 | +} |
0 commit comments