utils_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package trace
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "go.opentelemetry.io/otel/attribute"
  6. semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
  7. )
  8. func TestParseFullMethod(t *testing.T) {
  9. tests := []struct {
  10. fullMethod string
  11. name string
  12. attr []attribute.KeyValue
  13. }{
  14. {
  15. fullMethod: "/grpc.test.EchoService/Echo",
  16. name: "grpc.test.EchoService/Echo",
  17. attr: []attribute.KeyValue{
  18. semconv.RPCServiceKey.String("grpc.test.EchoService"),
  19. semconv.RPCMethodKey.String("Echo"),
  20. },
  21. }, {
  22. fullMethod: "/com.example.ExampleRmiService/exampleMethod",
  23. name: "com.example.ExampleRmiService/exampleMethod",
  24. attr: []attribute.KeyValue{
  25. semconv.RPCServiceKey.String("com.example.ExampleRmiService"),
  26. semconv.RPCMethodKey.String("exampleMethod"),
  27. },
  28. }, {
  29. fullMethod: "/MyCalcService.Calculator/Add",
  30. name: "MyCalcService.Calculator/Add",
  31. attr: []attribute.KeyValue{
  32. semconv.RPCServiceKey.String("MyCalcService.Calculator"),
  33. semconv.RPCMethodKey.String("Add"),
  34. },
  35. }, {
  36. fullMethod: "/MyServiceReference.ICalculator/Add",
  37. name: "MyServiceReference.ICalculator/Add",
  38. attr: []attribute.KeyValue{
  39. semconv.RPCServiceKey.String("MyServiceReference.ICalculator"),
  40. semconv.RPCMethodKey.String("Add"),
  41. },
  42. }, {
  43. fullMethod: "/MyServiceWithNoPackage/theMethod",
  44. name: "MyServiceWithNoPackage/theMethod",
  45. attr: []attribute.KeyValue{
  46. semconv.RPCServiceKey.String("MyServiceWithNoPackage"),
  47. semconv.RPCMethodKey.String("theMethod"),
  48. },
  49. }, {
  50. fullMethod: "/pkg.srv",
  51. name: "pkg.srv",
  52. attr: []attribute.KeyValue(nil),
  53. }, {
  54. fullMethod: "/pkg.srv/",
  55. name: "pkg.srv/",
  56. attr: []attribute.KeyValue{
  57. semconv.RPCServiceKey.String("pkg.srv"),
  58. },
  59. },
  60. }
  61. for _, test := range tests {
  62. n, a := ParseFullMethod(test.fullMethod)
  63. assert.Equal(t, test.name, n)
  64. assert.Equal(t, test.attr, a)
  65. }
  66. }