agent_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package trace
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. )
  7. func TestStartAgent(t *testing.T) {
  8. logx.Disable()
  9. const (
  10. endpoint1 = "localhost:1234"
  11. endpoint2 = "remotehost:1234"
  12. endpoint3 = "localhost:1235"
  13. endpoint4 = "localhost:1236"
  14. endpoint5 = "udp://localhost:6831"
  15. )
  16. c1 := Config{
  17. Name: "foo",
  18. }
  19. c2 := Config{
  20. Name: "bar",
  21. Endpoint: endpoint1,
  22. Batcher: kindJaeger,
  23. }
  24. c3 := Config{
  25. Name: "any",
  26. Endpoint: endpoint2,
  27. Batcher: kindZipkin,
  28. }
  29. c4 := Config{
  30. Name: "bla",
  31. Endpoint: endpoint3,
  32. Batcher: "otlp",
  33. }
  34. c5 := Config{
  35. Name: "grpc",
  36. Endpoint: endpoint3,
  37. Batcher: kindOtlpGrpc,
  38. }
  39. c6 := Config{
  40. Name: "otlphttp",
  41. Endpoint: endpoint4,
  42. Batcher: kindOtlpHttp,
  43. }
  44. c7 := Config{
  45. Name: "UDP",
  46. Endpoint: endpoint5,
  47. Batcher: kindJaeger,
  48. }
  49. StartAgent(c1)
  50. StartAgent(c1)
  51. StartAgent(c2)
  52. StartAgent(c3)
  53. StartAgent(c4)
  54. StartAgent(c5)
  55. StartAgent(c6)
  56. StartAgent(c7)
  57. lock.Lock()
  58. defer lock.Unlock()
  59. // because remotehost cannot be resolved
  60. assert.Equal(t, 5, len(agents))
  61. _, ok := agents[""]
  62. assert.True(t, ok)
  63. _, ok = agents[endpoint1]
  64. assert.True(t, ok)
  65. _, ok = agents[endpoint2]
  66. assert.False(t, ok)
  67. _, ok = agents[endpoint5]
  68. assert.True(t, ok)
  69. }