Explorar o código

SVI ДОбавление тестов; 8.3%

SVI %!s(int64=2) %!d(string=hai) anos
pai
achega
94e9bf4d3c

+ 0 - 1
internal/dict_topic/topic/topic_stat/topic_stat.go

@@ -30,7 +30,6 @@ func NewTopicStat(msg *netapi.TopicMsg) (*TopicStat, error) {
 			return nil, fmt.Errorf("NewTopicStat(): topicName is empty")
 		}
 	}
-
 	sf := &TopicStat{
 		topicName: alias.TopicName(msg.Topic),
 	}

+ 44 - 2
internal/dict_topic/topic/topic_stat/topic_stat_test.go

@@ -1,13 +1,18 @@
 package topic_stat
 
-import "testing"
+import (
+	"testing"
+
+	"p78git.ddns.net/svi/gobus/api/netapi"
+)
 
 /*
 	Тест для статистики топика
 */
 
 type tester struct {
-	t *testing.T
+	t    *testing.T
+	stat *TopicStat
 }
 
 func TestTopicStat(t *testing.T) {
@@ -21,6 +26,43 @@ func TestTopicStat(t *testing.T) {
 func (sf *tester) create() {
 	sf.t.Log("create")
 	sf.createBad1()
+	sf.createBad2()
+	sf.createGood1()
+}
+
+func (sf *tester) createGood1() {
+	sf.t.Log("createGood1")
+	var err error
+	msg := &netapi.TopicMsg{
+		Source:  0,
+		Topic:   "test_topic",
+		BinMsg:  []byte{},
+		StrUuid: "",
+	}
+	sf.stat, err = NewTopicStat(msg)
+	if err != nil {
+		sf.t.Fatalf("createGood1(): err=%v", err)
+	}
+	if sf.stat == nil {
+		sf.t.Fatalf("createGood1(): stat==nil")
+	}
+}
+
+func (sf *tester) createBad2() {
+	sf.t.Log("createBad2")
+	msg := &netapi.TopicMsg{
+		Source:  0,
+		Topic:   "",
+		BinMsg:  []byte{},
+		StrUuid: "",
+	}
+	stat, err := NewTopicStat(msg)
+	if err == nil {
+		sf.t.Fatalf("createBad2(): err==nil")
+	}
+	if stat != nil {
+		sf.t.Fatalf("createBad2(): stat!=nil")
+	}
 }
 
 // Нет сообщения