forked from CiscoDevNet/bigmuddy-network-telemetry-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodec_json_test.go
70 lines (55 loc) · 1.4 KB
/
codec_json_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// February 2016, cisco
//
// Copyright (c) 2016 by cisco Systems, Inc.
// All rights reserved.
//
//
package main
import (
"bytes"
"testing"
)
func TestCodecJSON(t *testing.T) {
var codecJSONTestSource testSource
err, p := getNewCodecJSON("JSON CODEC TEST")
if err != nil {
t.Errorf("Failed to get JSON codec [%v]", err)
return
}
testJSONMsg := []byte(`{"Name":"Alice","Body":"Hello","Test":1294706395881547000}`)
err, dMs := p.blockToDataMsgs(&codecJSONTestSource, testJSONMsg)
if err != nil {
t.Errorf("Failed to get messages from JSON stream [%v]", err)
return
}
dM := dMs[0]
err, b := p.dataMsgToBlock(dM)
if err == nil {
t.Errorf("Unexpected unsupported")
}
err, _ = dM.getMetaDataIdentifier()
if err != nil {
t.Errorf("Failed to retrieve identifier [%v]", err)
}
description := dM.getDataMsgDescription()
if description == "" {
t.Errorf("Failed to retrieve description")
}
err, _ = dM.getMetaDataPath()
if err == nil {
t.Errorf("Unexpected unsupported, no path to fetch")
}
err, b = dM.produceByteStream(&dataMsgStreamSpec{streamType: dMStreamGPB})
if err == nil {
t.Errorf("Unexpected unsupported GPB byte stream from JSON")
}
err, b = dM.produceByteStream(dataMsgStreamSpecDefault)
if err != nil {
t.Errorf("Failed to produce byte stream from dataMsg [%v]",
err)
}
if bytes.Compare(b, testJSONMsg) != 0 {
t.Errorf("Failed to extract expected data")
}
}