agent_test.go 987 B

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