The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/tsdb/jaeger/jaeger_test.go

89 lines
2.0 KiB

package jaeger
import (
"context"
"testing"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDataSourceInstanceSettings_TraceIdTimeEnabled(t *testing.T) {
tests := []struct {
name string
jsonData string
expectedEnabled bool
expectError bool
}{
{
name: "traceIdTimeParams enabled",
jsonData: `{
"traceIdTimeParams": {
"enabled": true
}
}`,
expectedEnabled: true,
expectError: false,
},
{
name: "traceIdTimeParams disabled",
jsonData: `{
"traceIdTimeParams": {
"enabled": false
}
}`,
expectedEnabled: false,
expectError: false,
},
{
name: "traceIdTimeParams not specified",
jsonData: `{}`,
expectedEnabled: false,
expectError: false,
},
{
name: "traceIdTimeParams without enabled",
jsonData: `{"traceIdTimeParams":{}}`,
expectedEnabled: false,
expectError: false,
},
{
name: "Invalid JSON",
jsonData: `{invalid json`,
expectedEnabled: false,
expectError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Create instance settings
settings := backend.DataSourceInstanceSettings{
JSONData: []byte(tt.jsonData),
URL: "http://localhost:16686",
}
// Create instance factory
factory := newInstanceSettings(httpclient.NewProvider())
instance, err := factory(context.Background(), settings)
if tt.expectError {
assert.Error(t, err)
return
}
require.NoError(t, err)
require.NotNil(t, instance)
// Get the datasource info
dsInfo, ok := instance.(*datasourceInfo)
require.True(t, ok)
require.NotNil(t, dsInfo)
// Verify the client's traceIdTimeEnabled parameter
assert.Equal(t, tt.expectedEnabled, dsInfo.JaegerClient.traceIdTimeEnabled)
})
}
}