forked from CiscoDevNet/bigmuddy-network-telemetry-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_test.go
88 lines (68 loc) · 1.68 KB
/
metrics_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// June 2016, cisco
//
// Copyright (c) 2016 by cisco Systems, Inc.
// All rights reserved.
//
//
package main
import (
"github.com/dlintw/goconf"
"testing"
"time"
)
func TestMetricsConfigureNegative(t *testing.T) {
var nc nodeConfig
mod := metricsOutputModuleNew()
cfg, err := goconf.ReadConfigFile("pipeline_test_bad.conf")
nc.config = cfg
badsections := []string{
"metricsbad_missingfilename",
"metricsbad_missingfile",
"metricsbad_badjson",
"metricsbad_missingoutput",
"metricsbad_unsupportedoutput",
"metricsbad_missingpushgw",
}
for _, section := range badsections {
err, _, _ = mod.configure(section, nc)
if err == nil {
t.Errorf("metrics section section [%v] should fail\n", section)
}
}
}
func TestMetricsConfigure(t *testing.T) {
var nc nodeConfig
var codecJSONTestSource testSource
mod := metricsOutputModuleNew()
cfg, err := goconf.ReadConfigFile("pipeline_test.conf")
nc.config = cfg
err, dChan, cChan := mod.configure("mymetrics", nc)
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]
dChan <- dM
time.Sleep(1 * time.Second)
//
// Send shutdown message
respChan := make(chan *ctrlMsg)
request := &ctrlMsg{
id: SHUTDOWN,
respChan: respChan,
}
cChan <- request
// Wait for ACK
ack := <-respChan
if ack.id != ACK {
t.Error("failed to recieve acknowledgement indicating shutdown complete")
}
}