Pārlūkot izejas kodu

SVI Добавление тестов словарю топиков; 28.0%

SVI 2 gadi atpakaļ
vecāks
revīzija
27b702c129

+ 2 - 2
internal/dict_topic/dict_topic.go

@@ -20,13 +20,13 @@ type DictTopic struct {
 }
 
 // NewDictTopic -- возвращает новый потокобезопасный словарь топиков
-func NewDictTopic() (*DictTopic, error) {
+func NewDictTopic() *DictTopic {
 	sf := &DictTopic{
 		dict:      make(map[alias.TopicName]types.ITopic),
 		dictProxy: make(map[alias.ClientName]types.IClientProxy),
 	}
 	_ = types.IDictTopic(sf)
-	return sf, nil
+	return sf
 }
 
 // Unsubscribe -- отписывает клиента от топиков

+ 6 - 1
internal/dict_topic/dict_topic_test.go

@@ -7,7 +7,8 @@ import "testing"
 */
 
 type tester struct {
-	t *testing.T
+	t         *testing.T
+	dictTopic *DictTopic
 }
 
 func TestAny(t *testing.T) {
@@ -19,4 +20,8 @@ func TestAny(t *testing.T) {
 
 func (sf *tester) create() {
 	sf.t.Log("create")
+	sf.dictTopic = NewDictTopic()
+	if sf.dictTopic == nil {
+		sf.t.Fatalf("create(): dictTopic==nil")
+	}
 }

+ 7 - 6
internal/service/service.go

@@ -25,15 +25,16 @@ type Service struct {
 // NewSevice -- взвращае тновый сервис
 func NewSevice() (*Service, error) {
 	log.Printf("NewService()\n")
+	ctxBg := context.Background()
+	ctx, fnCancel := context.WithCancel(ctxBg)
 	sf := &Service{
-		ctxBg: context.Background(),
+		ctxBg:     ctxBg,
+		ctx:       ctx,
+		fnCancel:  fnCancel,
+		dictTopic: dict_topic.NewDictTopic(),
 	}
-	sf.ctx, sf.fnCancel = context.WithCancel(sf.ctxBg)
+
 	var err error
-	sf.dictTopic, err = dict_topic.NewDictTopic()
-	if err != nil {
-		return nil, fmt.Errorf("NewService(): in create IDictTopic, err=\n\t%w", err)
-	}
 	sf.dictClientProxyBuffer, err = dict_client_proxy_buffer.NewDictClientProxyBuffer(sf)
 	if err != nil {
 		return nil, fmt.Errorf("NewService(): in create IDictClientProxyBuffer, err=\n\t%w", err)