forked from Juniper/jtimon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflux_test.go
91 lines (83 loc) · 2.88 KB
/
influx_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
89
90
91
/*
* Copyright (c) 2018, Juniper Networks, Inc.
* All rights reserved.
*/
package main
import (
"reflect"
"regexp"
"testing"
)
func TestSpitTagsNPath(t *testing.T) {
jctx := &JCtx{
influxCtx: InfluxCtx{
re: regexp.MustCompile(MatchExpression),
},
}
data := []struct {
input string
xmlpath string
tags map[string]string
}{
{
"/path/without/tags",
"/path/without/tags",
map[string]string{},
},
{
"/interfaces/interface[name='ge-0/0/0']/state/admin-status/",
"/interfaces/interface/state/admin-status/",
map[string]string{
"/interfaces/interface/@name": "ge-0/0/0",
},
},
{
"/interfaces/interface[name='ge-0/0/0']/subinterfaces/subinterface[index='9']/state/admin-status",
"/interfaces/interface/subinterfaces/subinterface/state/admin-status",
map[string]string{
"/interfaces/interface/@name": "ge-0/0/0",
"/interfaces/interface/subinterfaces/subinterface/@index": "9",
},
},
{
"/junos/chassis/cmerror/counters[name='/fpc/1/pfe/0/cm/0/CM0/0/CM_CMERROR_FABRIC_REMOTE_PFE_RATE']/error",
"/junos/chassis/cmerror/counters/error",
map[string]string{
"/junos/chassis/cmerror/counters/@name": "/fpc/1/pfe/0/cm/0/CM0/0/CM_CMERROR_FABRIC_REMOTE_PFE_RATE",
},
},
}
for _, d := range data {
gotxmlpath, gottags := spitTagsNPath(jctx, d.input)
if gotxmlpath != d.xmlpath {
t.Errorf("splitTagsNPath xmlpath failed, got: %s, want: %s", gotxmlpath, d.xmlpath)
}
if !reflect.DeepEqual(gottags, d.tags) {
t.Errorf("splitTagsNPath tags failed, got: %v, want: %v", gottags, d.tags)
}
}
}
func TestSubscriptionPathFromPath(t *testing.T) {
paths := []struct {
input string
exp string
}{
{"", ""},
{"sensor_1008:/lacp/:/lacp/:lacpd", "/lacp/"},
{"sensor_1009:/lldp/:/lldp/:l2cpd", "/lldp/"},
{"sensor_1000_5_1:/interfaces/:/interfaces/:xmlproxyd", "/interfaces/"},
{"sensor_1000_1_1:/junos/system/linecard/interface/:/interfaces/:PFE", "/interfaces/"},
{"sensor_1002:/arp-information/ipv4/:/arp-information/ipv4/:mib2d", "/arp-information/ipv4/"},
{"sensor_1000_1_2:/junos/system/linecard/interface/logical/usage/:/interfaces/:PFE", "/interfaces/"},
{"sensor_1004:/junos/system/linecard/firewall/:/junos/system/linecard/firewall/:PFE", "/junos/system/linecard/firewall/"},
{"sensor_1018:/junos/system/linecard/npu/memory/:/junos/system/linecard/npu/memory/:PFE", "/junos/system/linecard/npu/memory/"},
{"sensor_1006:/interfaces/interface/state/ifindex/:/interfaces/interface/state/ifindex/:mib2d", "/interfaces/interface/state/ifindex/"},
{"sensor_1010:/network-instances/network-instance/mpls/:/network-instances/network-instance/mpls/:rpd", "/network-instances/network-instance/mpls/"},
}
for _, path := range paths {
got := SubscriptionPathFromPath(path.input)
if got != path.exp {
t.Errorf("SubscriptionPathFromPath failed, got: %s, want: %s", got, path.exp)
}
}
}