agent_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. OtlpHttpPath: "/v1/traces",
  50. }
  51. c7 := Config{
  52. Name: "UDP",
  53. Endpoint: endpoint5,
  54. Batcher: kindJaeger,
  55. }
  56. StartAgent(c1)
  57. StartAgent(c1)
  58. StartAgent(c2)
  59. StartAgent(c3)
  60. StartAgent(c4)
  61. StartAgent(c5)
  62. StartAgent(c6)
  63. StartAgent(c7)
  64. lock.Lock()
  65. defer lock.Unlock()
  66. // because remotehost cannot be resolved
  67. assert.Equal(t, 5, len(agents))
  68. _, ok := agents[""]
  69. assert.True(t, ok)
  70. _, ok = agents[endpoint1]
  71. assert.True(t, ok)
  72. _, ok = agents[endpoint2]
  73. assert.False(t, ok)
  74. _, ok = agents[endpoint5]
  75. assert.True(t, ok)
  76. }