detect_test.go 728 B

1234567891011121314151617181920212223242526
  1. package collector
  2. import (
  3. "testing"
  4. "go-common/app/service/main/dapper/model"
  5. )
  6. func TestPeerServiceDetect(t *testing.T) {
  7. detect := NewPeerServiceDetectProcesser(map[string]map[string]struct{}{
  8. "s_a": {
  9. "o_1": struct{}{},
  10. "o_11": struct{}{},
  11. },
  12. "s_b": {"o_2": struct{}{}},
  13. "s_c": {"o_21": struct{}{}},
  14. })
  15. sp1, _ := model.FromProtoSpan(&model.ProtoSpan{ServiceName: "xxx", OperationName: "o_1"}, false)
  16. detect.Process(sp1)
  17. if sp1.StringTag("peer.service") != "s_a" && sp1.BoolTag("_auto.peer.service") {
  18. t.Errorf("expect get s_a get %s", sp1.StringTag("peer.service"))
  19. }
  20. if err := detect.Process(&model.Span{ServiceName: "hh", OperationName: ""}); err != nil {
  21. t.Errorf("expect get noting")
  22. }
  23. }