agent_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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: "otlpgrpc",
  36. Endpoint: endpoint3,
  37. Batcher: kindOtlpGrpc,
  38. OtlpHeaders: map[string]string{
  39. "uptrace-dsn": "http://project2_secret_token@localhost:14317/2",
  40. },
  41. }
  42. c6 := Config{
  43. Name: "otlphttp",
  44. Endpoint: endpoint4,
  45. Batcher: kindOtlpHttp,
  46. OtlpHeaders: map[string]string{
  47. "uptrace-dsn": "http://project2_secret_token@localhost:14318/2",
  48. },
  49. }
  50. c7 := Config{
  51. Name: "UDP",
  52. Endpoint: endpoint5,
  53. Batcher: kindJaeger,
  54. }
  55. StartAgent(c1)
  56. StartAgent(c1)
  57. StartAgent(c2)
  58. StartAgent(c3)
  59. StartAgent(c4)
  60. StartAgent(c5)
  61. StartAgent(c6)
  62. StartAgent(c7)
  63. lock.Lock()
  64. defer lock.Unlock()
  65. // because remotehost cannot be resolved
  66. assert.Equal(t, 5, len(agents))
  67. _, ok := agents[""]
  68. assert.True(t, ok)
  69. _, ok = agents[endpoint1]
  70. assert.True(t, ok)
  71. _, ok = agents[endpoint2]
  72. assert.False(t, ok)
  73. _, ok = agents[endpoint5]
  74. assert.True(t, ok)
  75. }