agent_test.go 955 B

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