Skip to content

Commit

Permalink
Refactor some shared code
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney committed Jul 28, 2023
1 parent 2082d49 commit ce3ec02
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions pkg/logcli/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/grafana/loki/pkg/logcli/volume"
"github.com/grafana/loki/pkg/loghttp"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logqlmodel/stats"
"github.com/grafana/loki/pkg/querier/queryrange"
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
"github.com/prometheus/common/model"
Expand Down Expand Up @@ -181,7 +180,7 @@ type mockLokiHTTPServer struct {
server *http.Server
tenantID string
now time.Time
then time.Time
then time.Time
}

func NewMockLokiHTTPServer(t *testing.T, now, then time.Time) *mockLokiHTTPServer {
Expand All @@ -205,14 +204,15 @@ func (s *mockLokiHTTPServer) getTenantIDUnsafe() string {

func (s *mockLokiHTTPServer) Run(t *testing.T) {
var mux http.ServeMux
mux.HandleFunc("/loki/api/v1/index/volume", func(w http.ResponseWriter, request *http.Request) {
labels := labels.Labels{
{
Name: "foo",
Value: "bar",
},
}
labels := labels.Labels{
{
Name: "foo",
Value: "bar",
},
}
codec := queryrange.Codec{}

mux.HandleFunc("/loki/api/v1/index/volume", func(w http.ResponseWriter, request *http.Request) {
volume := queryrange.LokiPromResponse{
Response: &queryrangebase.PrometheusResponse{
Status: loghttp.QueryStatusSuccess,
Expand All @@ -231,10 +231,8 @@ func (s *mockLokiHTTPServer) Run(t *testing.T) {
},
},
},
Statistics: stats.Result{},
}

codec := queryrange.Codec{}
resp, err := codec.EncodeResponse(request.Context(), request, &volume)
require.NoError(t, err)
bytes, err := io.ReadAll(resp.Body)
Expand All @@ -245,13 +243,6 @@ func (s *mockLokiHTTPServer) Run(t *testing.T) {
})

mux.HandleFunc("/loki/api/v1/index/volume_range", func(w http.ResponseWriter, request *http.Request) {
labels := labels.Labels{
{
Name: "foo",
Value: "bar",
},
}

volume := queryrange.LokiPromResponse{
Response: &queryrangebase.PrometheusResponse{
Status: loghttp.QueryStatusSuccess,
Expand All @@ -274,10 +265,8 @@ func (s *mockLokiHTTPServer) Run(t *testing.T) {
},
},
},
Statistics: stats.Result{},
}

codec := queryrange.Codec{}
resp, err := codec.EncodeResponse(request.Context(), request, &volume)
require.NoError(t, err)
bytes, err := io.ReadAll(resp.Body)
Expand Down

0 comments on commit ce3ec02

Please sign in to comment.