Browse code

Fix a error of the function 'CopyMessage' in 'daemon/logger/logger.go'

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>

add a test for 'CopyMessage'

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>

update

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
(cherry picked from commit 3b82eac65fc365a89f64ccaba98f8f3b5c9c5787)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

Yanqiang Miao authored on 2016/11/24 18:02:48
Showing 2 changed files
... ...
@@ -49,7 +49,7 @@ func CopyMessage(msg *Message) *Message {
49 49
 	m.Timestamp = msg.Timestamp
50 50
 	m.Partial = msg.Partial
51 51
 	m.Attrs = make(LogAttributes)
52
-	for k, v := range m.Attrs {
52
+	for k, v := range msg.Attrs {
53 53
 		m.Attrs[k] = v
54 54
 	}
55 55
 	return m
56 56
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+package logger
1
+
2
+import (
3
+	"reflect"
4
+	"testing"
5
+	"time"
6
+)
7
+
8
+func TestCopyMessage(t *testing.T) {
9
+	msg := &Message{
10
+		Line:      []byte("test line."),
11
+		Source:    "stdout",
12
+		Timestamp: time.Now(),
13
+		Attrs: LogAttributes{
14
+			"key1": "val1",
15
+			"key2": "val2",
16
+			"key3": "val3",
17
+		},
18
+		Partial: true,
19
+	}
20
+
21
+	m := CopyMessage(msg)
22
+	if !reflect.DeepEqual(m, msg) {
23
+		t.Fatalf("CopyMessage failed to copy message")
24
+	}
25
+}