log_topic_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package log_topic
  2. import (
  3. "testing"
  4. "gitp78su.ipnodns.ru/svi/kern/krn/kbus/kbus_local/client_bus_local"
  5. "gitp78su.ipnodns.ru/svi/kern/krn/kctx"
  6. )
  7. type tester struct {
  8. t *testing.T
  9. }
  10. func TestLogTopic(t *testing.T) {
  11. sf := &tester{
  12. t: t,
  13. }
  14. sf.new()
  15. }
  16. // Создаёт новый торик для логирования
  17. func (sf *tester) new() {
  18. sf.t.Log("new")
  19. sf.newBad1()
  20. sf.newGood1()
  21. }
  22. // Правильное создание топика
  23. func (sf *tester) newGood1() {
  24. sf.t.Log("newGood1")
  25. busClient := client_bus_local.NewClientBusLocal()
  26. client := NewLogTopic("test_topic", busClient)
  27. res := client.Pub([]byte("test_msg"))
  28. if res.IsErr() {
  29. sf.t.Fatalf("newGood1(): err=%v", res.Err())
  30. }
  31. ctx := kctx.GetKernelCtx()
  32. ctx.Cancel()
  33. ctx.Wg().Wait()
  34. res = client.Pub([]byte("test_msg"))
  35. if !res.IsErr() {
  36. sf.t.Fatalf("newGood1(): err==nil")
  37. }
  38. }
  39. // Нет топика лога
  40. func (sf *tester) newBad1() {
  41. defer func() {
  42. if _panic := recover(); _panic == nil {
  43. sf.t.Fatalf("newBad1(): panic==nil")
  44. }
  45. }()
  46. _ = NewLogTopic("", nil)
  47. }