Fix tests

This commit is contained in:
André Pereira
2023-10-12 14:05:01 +01:00
parent 8337cce059
commit 0a7353dab0
6 changed files with 25 additions and 6 deletions
@@ -5,12 +5,15 @@ import (
"testing"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/stretchr/testify/require"
)
// This is where the tests for the datasource backend live.
func Test_QueryData(t *testing.T) {
ds := PyroscopeDatasource{}
ds := PyroscopeDatasource{
tracer: tracing.InitializeTracerForTest(),
}
resp, err := ds.QueryData(
context.Background(),
@@ -32,6 +35,7 @@ func Test_QueryData(t *testing.T) {
func Test_CallResource(t *testing.T) {
ds := &PyroscopeDatasource{
client: &FakeClient{},
tracer: tracing.InitializeTracerForTest(),
}
t.Run("series resource", func(t *testing.T) {
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/bufbuild/connect-go"
"github.com/grafana/grafana/pkg/infra/tracing"
googlev1 "github.com/grafana/pyroscope/api/gen/proto/go/google/v1"
querierv1 "github.com/grafana/pyroscope/api/gen/proto/go/querier/v1"
typesv1 "github.com/grafana/pyroscope/api/gen/proto/go/types/v1"
@@ -15,6 +16,7 @@ func Test_PyroscopeClient(t *testing.T) {
connectClient := &FakePyroscopeConnectClient{}
client := &PyroscopeClient{
connectClient: connectClient,
tracer: tracing.InitializeTracerForTest(),
}
t.Run("GetSeries", func(t *testing.T) {
@@ -7,6 +7,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/stretchr/testify/require"
)
@@ -15,6 +16,7 @@ func Test_query(t *testing.T) {
client := &FakeClient{}
ds := &PyroscopeDatasource{
client: client,
tracer: tracing.InitializeTracerForTest(),
}
pCtx := backend.PluginContext{
+5 -1
View File
@@ -5,12 +5,15 @@ import (
"testing"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/stretchr/testify/require"
)
// This is where the tests for the datasource backend live.
func Test_QueryData(t *testing.T) {
ds := ParcaDatasource{}
ds := ParcaDatasource{
tracer: tracing.InitializeTracerForTest(),
}
resp, err := ds.QueryData(
context.Background(),
@@ -35,6 +38,7 @@ func Test_QueryData(t *testing.T) {
func Test_CallResource(t *testing.T) {
ds := &ParcaDatasource{
client: &FakeClient{},
tracer: tracing.InitializeTracerForTest(),
}
t.Run("labels resource", func(t *testing.T) {
+2
View File
@@ -11,6 +11,7 @@ import (
"github.com/bufbuild/connect-go"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"
)
@@ -19,6 +20,7 @@ import (
func Test_query(t *testing.T) {
ds := &ParcaDatasource{
client: &FakeClient{},
tracer: tracing.InitializeTracerForTest(),
}
dataQuery := backend.DataQuery{
+9 -4
View File
@@ -12,16 +12,19 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/tsdb/tempo/kinds/dataquery"
"github.com/grafana/tempo/pkg/tempopb"
"google.golang.org/grpc/metadata"
)
func TestProcessStream_ValidInput_ReturnsNoError(t *testing.T) {
service := &Service{}
service := &Service{
tracer: tracing.InitializeTracerForTest(),
}
searchClient := &mockStreamer{}
streamSender := &mockSender{}
err := service.processStream(searchClient, streamSender)
err := service.processStream(context.Background(), searchClient, streamSender)
if err != nil {
t.Errorf("Expected no error, but got %s", err)
}
@@ -30,10 +33,11 @@ func TestProcessStream_InvalidInput_ReturnsError(t *testing.T) {
logger := log.New("tsdb.tempo.test")
service := &Service{
logger: logger,
tracer: tracing.InitializeTracerForTest(),
}
searchClient := &mockStreamer{err: errors.New("invalid input")}
streamSender := &mockSender{}
err := service.processStream(searchClient, streamSender)
err := service.processStream(context.Background(), searchClient, streamSender)
if err != nil {
if !strings.Contains(err.Error(), "invalid input") {
t.Errorf("Expected error message to contain 'invalid input', but got %s", err)
@@ -44,6 +48,7 @@ func TestProcessStream_ValidInput_ReturnsExpectedOutput(t *testing.T) {
logger := log.New("tsdb.tempo.test")
service := &Service{
logger: logger,
tracer: tracing.InitializeTracerForTest(),
}
searchClient := &mockStreamer{
tracingMetadata: []*tempopb.TraceSearchMetadata{
@@ -109,7 +114,7 @@ func TestProcessStream_ValidInput_ReturnsExpectedOutput(t *testing.T) {
},
}
streamSender := &mockSender{}
err := service.processStream(searchClient, streamSender)
err := service.processStream(context.Background(), searchClient, streamSender)
if err != nil {
t.Errorf("Expected no error, but got %s", err)
return