(t *testing.T)
| 77 | } |
| 78 | |
| 79 | func TestQueryTraceWithRange(t *testing.T) { |
| 80 | trace := &tempopb.Trace{} |
| 81 | t.Run("returns an error if start time is greater than end time", func(t *testing.T) { |
| 82 | client := New("www.tempo.com", "1000") |
| 83 | response, err := client.QueryTraceWithRange(context.Background(), "notfound", 3000, 2000) |
| 84 | |
| 85 | assert.Error(t, err) |
| 86 | assert.Nil(t, response) |
| 87 | }) |
| 88 | |
| 89 | t.Run("returns a trace with range when is found", func(t *testing.T) { |
| 90 | mockTransport := MockRoundTripper(func(req *http.Request) *http.Response { |
| 91 | assert.Equal(t, "www.tempo.com/api/traces/100?end=2000&start=1000", fmt.Sprint(req.URL)) |
| 92 | assert.Equal(t, "application/protobuf", req.Header.Get("Accept")) |
| 93 | response, _ := proto.Marshal(trace) |
| 94 | return &http.Response{ |
| 95 | StatusCode: 200, |
| 96 | Body: io.NopCloser(bytes.NewReader(response)), |
| 97 | } |
| 98 | }) |
| 99 | |
| 100 | client := New("www.tempo.com", "1000") |
| 101 | client.WithTransport(mockTransport) |
| 102 | response, err := client.QueryTraceWithRange(context.Background(), "100", 1000, 2000) |
| 103 | |
| 104 | assert.NoError(t, err) |
| 105 | assert.True(t, proto.Equal(trace, response)) |
| 106 | }) |
| 107 | |
| 108 | t.Run("returns a trace with range not found error on 404", func(t *testing.T) { |
| 109 | mockTransport := MockRoundTripper(func(_ *http.Request) *http.Response { |
| 110 | return &http.Response{ |
| 111 | StatusCode: 404, |
| 112 | Body: nil, |
| 113 | } |
| 114 | }) |
| 115 | |
| 116 | client := New("www.tempo.com", "1000") |
| 117 | client.WithTransport(mockTransport) |
| 118 | response, err := client.QueryTraceWithRange(context.Background(), "notfound", 1000, 2000) |
| 119 | |
| 120 | assert.Error(t, err) |
| 121 | assert.Nil(t, response) |
| 122 | }) |
| 123 | } |
nothing calls this directly
no test coverage detected