mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* metrics-generator: handle missing dimensions * linting: no explicit code allowed!
102 lines
1.7 KiB
Go
102 lines
1.7 KiB
Go
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
v1_common "github.com/grafana/tempo/pkg/tempopb/common/v1"
|
|
)
|
|
|
|
func TestFindServiceName(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
attributes []*v1_common.KeyValue
|
|
expectedServiceName string
|
|
expectedOk bool
|
|
}{
|
|
{
|
|
"empty attributes",
|
|
nil,
|
|
"",
|
|
false,
|
|
},
|
|
{
|
|
"service name",
|
|
[]*v1_common.KeyValue{
|
|
{
|
|
Key: "cluster",
|
|
Value: &v1_common.AnyValue{
|
|
Value: &v1_common.AnyValue_StringValue{
|
|
StringValue: "test",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Key: "service.name",
|
|
Value: &v1_common.AnyValue{
|
|
Value: &v1_common.AnyValue_StringValue{
|
|
StringValue: "my-service",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"my-service",
|
|
true,
|
|
},
|
|
{
|
|
"service name",
|
|
[]*v1_common.KeyValue{
|
|
{
|
|
Key: "service.name",
|
|
Value: &v1_common.AnyValue{
|
|
Value: &v1_common.AnyValue_StringValue{
|
|
StringValue: "",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"",
|
|
true,
|
|
},
|
|
{
|
|
"no service name",
|
|
[]*v1_common.KeyValue{
|
|
{
|
|
Key: "cluster",
|
|
Value: &v1_common.AnyValue{
|
|
Value: &v1_common.AnyValue_StringValue{
|
|
StringValue: "test",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"",
|
|
false,
|
|
},
|
|
{
|
|
"service name is other type",
|
|
[]*v1_common.KeyValue{
|
|
{
|
|
Key: "service.name",
|
|
Value: &v1_common.AnyValue{
|
|
Value: &v1_common.AnyValue_BoolValue{
|
|
BoolValue: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
"false",
|
|
true,
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
svcName, ok := FindServiceName(tc.attributes)
|
|
|
|
assert.Equal(t, tc.expectedOk, ok)
|
|
assert.Equal(t, tc.expectedServiceName, svcName)
|
|
})
|
|
}
|
|
}
|