1
0

agent_test.go 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. StartAgent(c1)
  33. StartAgent(c1)
  34. StartAgent(c2)
  35. StartAgent(c3)
  36. StartAgent(c4)
  37. lock.Lock()
  38. defer lock.Unlock()
  39. // because remotehost cannot be resolved
  40. assert.Equal(t, 2, len(agents))
  41. _, ok := agents[""]
  42. assert.True(t, ok)
  43. _, ok = agents[endpoint1]
  44. assert.True(t, ok)
  45. _, ok = agents[endpoint2]
  46. assert.False(t, ok)
  47. }