agent_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. )
  15. c1 := Config{
  16. Name: "foo",
  17. }
  18. c2 := Config{
  19. Name: "bar",
  20. Endpoint: endpoint1,
  21. Batcher: kindJaeger,
  22. }
  23. c3 := Config{
  24. Name: "any",
  25. Endpoint: endpoint2,
  26. Batcher: kindZipkin,
  27. }
  28. c4 := Config{
  29. Name: "bla",
  30. Endpoint: endpoint3,
  31. Batcher: "otlp",
  32. }
  33. c5 := Config{
  34. Name: "grpc",
  35. Endpoint: endpoint3,
  36. Batcher: kindOtlpGrpc,
  37. }
  38. c6 := Config{
  39. Name: "otlphttp",
  40. Endpoint: endpoint4,
  41. Batcher: kindOtlpHttp,
  42. }
  43. StartAgent(c1)
  44. StartAgent(c1)
  45. StartAgent(c2)
  46. StartAgent(c3)
  47. StartAgent(c4)
  48. StartAgent(c5)
  49. StartAgent(c6)
  50. lock.Lock()
  51. defer lock.Unlock()
  52. // because remotehost cannot be resolved
  53. assert.Equal(t, 4, len(agents))
  54. _, ok := agents[""]
  55. assert.True(t, ok)
  56. _, ok = agents[endpoint1]
  57. assert.True(t, ok)
  58. _, ok = agents[endpoint2]
  59. assert.False(t, ok)
  60. }