...
1
2
3
4 package internal
5
6 import (
7 "testing"
8
9 "go.opentelemetry.io/otel/attribute"
10 semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
11
12 "github.com/stretchr/testify/assert"
13 )
14
15 func TestParseFullMethod(t *testing.T) {
16 cases := []struct {
17 input string
18 expectedName string
19 expectedAttrs []attribute.KeyValue
20 }{
21 {
22 input: "no_slash/method",
23 expectedName: "no_slash/method",
24 },
25 {
26 input: "/slash_but_no_second_slash",
27 expectedName: "slash_but_no_second_slash",
28 },
29 {
30 input: "/service_only/",
31 expectedName: "service_only/",
32 expectedAttrs: []attribute.KeyValue{
33 semconv.RPCService("service_only"),
34 },
35 },
36 {
37 input: "//method_only",
38 expectedName: "/method_only",
39 expectedAttrs: []attribute.KeyValue{
40 semconv.RPCMethod("method_only"),
41 },
42 },
43 {
44 input: "/service/method",
45 expectedName: "service/method",
46 expectedAttrs: []attribute.KeyValue{
47 semconv.RPCService("service"),
48 semconv.RPCMethod("method"),
49 },
50 },
51 }
52 for _, tc := range cases {
53 t.Run(tc.input, func(t *testing.T) {
54 name, attrs := ParseFullMethod(tc.input)
55 assert.Equal(t, tc.expectedName, name)
56 assert.Equal(t, tc.expectedAttrs, attrs)
57 })
58 }
59 }
60
View as plain text