mock_hand_sub_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package mock_hand_sub_local
  2. import (
  3. "strings"
  4. "testing"
  5. "gitp78su.ipnodns.ru/svi/kern/v4/lev0/defs"
  6. )
  7. type tester struct {
  8. t *testing.T
  9. hand *MockHandlerSub
  10. }
  11. func TestMockHandleServe(t *testing.T) {
  12. sf := &tester{
  13. t: t,
  14. }
  15. sf.new()
  16. sf.back()
  17. }
  18. // Проверка обратного вызова.
  19. func (sf *tester) back() {
  20. sf.t.Log("back")
  21. sf.backGood1()
  22. }
  23. func (sf *tester) backGood1() {
  24. sf.t.Log("backGood1")
  25. sf.hand.FnBack([]byte("test_msg"))
  26. if sf.hand.Msg() != "test_msg" {
  27. sf.t.Fatalf("backGood1(): binMsg(%v)!='test_msg'", string(sf.hand.Msg_))
  28. }
  29. }
  30. // Создание мок-обработчика запросов.
  31. func (sf *tester) new() {
  32. sf.t.Log("new")
  33. sf.newGood1()
  34. }
  35. var (
  36. qTopicTest = defs.NewTopic("test_topic")
  37. )
  38. func (sf *tester) newGood1() {
  39. sf.t.Log("newGood1")
  40. sf.hand = NewMockHandlerSub(qTopicTest, "test_name")
  41. if sf.hand == nil {
  42. sf.t.Fatalf("newGood1(): handler==nil")
  43. }
  44. if name := sf.hand.Name(); !strings.Contains(name.Get(), "test_name_") {
  45. sf.t.Fatalf("newGood1(): name(%v)!='test_name_'", name)
  46. }
  47. if topic := sf.hand.Topic(); topic.Get() != "test_topic" {
  48. sf.t.Fatalf("newGood1(): topic(%v)!='test_topic'", topic)
  49. }
  50. if msg := sf.hand.Msg(); msg != "" {
  51. sf.t.Fatalf("newGood1(): msg not empty")
  52. }
  53. }