| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package log_topic
- import (
- "testing"
- "gitp78su.ipnodns.ru/svi/kern/krn/kbus/kbus_local/client_bus_local"
- "gitp78su.ipnodns.ru/svi/kern/krn/kctx"
- )
- type tester struct {
- t *testing.T
- }
- func TestLogTopic(t *testing.T) {
- sf := &tester{
- t: t,
- }
- sf.new()
- }
- // Создаёт новый торик для логирования
- func (sf *tester) new() {
- sf.t.Log("new")
- sf.newBad1()
- sf.newGood1()
- }
- // Правильное создание топика
- func (sf *tester) newGood1() {
- sf.t.Log("newGood1")
- busClient := client_bus_local.NewClientBusLocal()
- client := NewLogTopic("test_topic", busClient)
- res := client.Pub([]byte("test_msg"))
- if res.IsErr() {
- sf.t.Fatalf("newGood1(): err=%v", res.Error())
- }
- ctx := kctx.GetKernelCtx()
- ctx.Cancel()
- ctx.Wg().Wait()
- res = client.Pub([]byte("test_msg"))
- if !res.IsErr() {
- sf.t.Fatalf("newGood1(): err==nil")
- }
- }
- // Нет топика лога
- func (sf *tester) newBad1() {
- defer func() {
- if _panic := recover(); _panic == nil {
- sf.t.Fatalf("newBad1(): panic==nil")
- }
- }()
- _ = NewLogTopic("", nil)
- }
|