Skip to content

Commit 9e89616

Browse files
UT for issues found during CCL
1 parent b45327b commit 9e89616

File tree

3 files changed

+258
-3
lines changed

3 files changed

+258
-3
lines changed

config_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ func TestValidateConfig(t *testing.T) {
5757
name string
5858
error bool
5959
}{
60-
{"tests/data/noerror.json", false}, // no error
61-
{"tests/data/error.jso", true}, // file does not exists
62-
{"tests/data/error.json", true}, // syntax error in JSON file
60+
{"tests/data/noerror.json", false}, // no error
61+
{"tests/data/noerror_internal_jtimon.json", false}, // no error
62+
{"tests/data/error.jso", true}, // file does not exists
63+
{"tests/data/error.json", true}, // syntax error in JSON file
6364
}
6465

6566
for _, test := range tests {

subscribe_gnmi_test.go

+231
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,237 @@ func TestGnmiHandleResponse(t *testing.T) {
617617
*noppgoroutines = false
618618
}
619619

620+
func TestMeasurementNameInGnmiParseHeader(t *testing.T) {
621+
*noppgoroutines = true
622+
*prom = true
623+
gGnmiUnitTestCoverage = true
624+
625+
var hdrInputExtTerseHeaderForIPAFT = gnmi_juniper_header_ext.GnmiJuniperTelemetryHeaderExtension{
626+
SequenceNumber: 1,
627+
}
628+
629+
hdrInputExtTerseHeaderForIPAFTBytes, err := proto.Marshal(&hdrInputExtTerseHeaderForIPAFT)
630+
if err != nil {
631+
t.Errorf("Error marshalling header for ext isync case: %v", err)
632+
}
633+
634+
var hdrInputExtHeaderWithSubscribedPath = gnmi_juniper_header_ext.GnmiJuniperTelemetryHeaderExtension{
635+
SequenceNumber: 1, SubscribedPath: "/x/y/z/",
636+
}
637+
638+
hdrInputExtHeaderWithSubscribedPathBytes, err := proto.Marshal(&hdrInputExtHeaderWithSubscribedPath)
639+
if err != nil {
640+
t.Errorf("Error marshalling header for ext isync case: %v", err)
641+
}
642+
643+
tests := []struct {
644+
name string
645+
jctx *JCtx
646+
rsp *gnmi.SubscribeResponse
647+
parseOutput *gnmiParseOutputT
648+
expectedMeasurementName string
649+
err bool
650+
}{
651+
{
652+
name: "rsp-check-juniper-terse-header-ipaft-with-prefix",
653+
expectedMeasurementName: "/network-instances/network-instance/afts/next-hop-groups/next-hop-group/",
654+
err: false,
655+
jctx: &JCtx{
656+
config: Config{
657+
Host: "127.0.0.1",
658+
Port: 32767,
659+
Log: LogConfig{
660+
Verbose: true,
661+
},
662+
},
663+
},
664+
parseOutput: &gnmiParseOutputT{
665+
kvpairs: map[string]string{},
666+
xpaths: map[string]interface{}{},
667+
},
668+
rsp: &gnmi.SubscribeResponse{
669+
Extension: []*gnmi_ext1.Extension{
670+
{
671+
Ext: &gnmi_ext1.Extension_RegisteredExt{
672+
RegisteredExt: &gnmi_ext1.RegisteredExtension{
673+
Id: gnmi_ext1.ExtensionID_EID_JUNIPER_TELEMETRY_HEADER,
674+
Msg: hdrInputExtTerseHeaderForIPAFTBytes,
675+
},
676+
},
677+
},
678+
},
679+
Response: &gnmi.SubscribeResponse_Update{
680+
Update: &gnmi.Notification{
681+
Timestamp: 1589476296083000000,
682+
Prefix: &gnmi.Path{
683+
Origin: "",
684+
Elem: []*gnmi.PathElem{
685+
{Name: "network-instances"},
686+
{Name: "network-instance", Key: map[string]string{"name": "DEFAULT"}},
687+
{Name: "afts"},
688+
{Name: "next-hop-groups"},
689+
{Name: "next-hop-group", Key: map[string]string{"id": "1"}},
690+
},
691+
},
692+
Update: []*gnmi.Update{
693+
{
694+
Path: &gnmi.Path{
695+
Origin: "",
696+
Elem: []*gnmi.PathElem{
697+
{Name: "state"},
698+
{Name: "dummyfield"},
699+
},
700+
},
701+
Val: &gnmi.TypedValue{
702+
Value: &gnmi.TypedValue_StringVal{StringVal: "dummyval"},
703+
},
704+
},
705+
},
706+
},
707+
},
708+
},
709+
},
710+
{
711+
name: "rsp-check-juniper-terse-header-without-prefix",
712+
expectedMeasurementName: "/",
713+
err: false,
714+
jctx: &JCtx{
715+
config: Config{
716+
Host: "127.0.0.1",
717+
Port: 32767,
718+
Log: LogConfig{
719+
Verbose: true,
720+
},
721+
},
722+
},
723+
parseOutput: &gnmiParseOutputT{
724+
kvpairs: map[string]string{},
725+
xpaths: map[string]interface{}{},
726+
},
727+
rsp: &gnmi.SubscribeResponse{
728+
Extension: []*gnmi_ext1.Extension{
729+
{
730+
Ext: &gnmi_ext1.Extension_RegisteredExt{
731+
RegisteredExt: &gnmi_ext1.RegisteredExtension{
732+
Id: gnmi_ext1.ExtensionID_EID_JUNIPER_TELEMETRY_HEADER,
733+
Msg: hdrInputExtTerseHeaderForIPAFTBytes,
734+
},
735+
},
736+
},
737+
},
738+
Response: &gnmi.SubscribeResponse_Update{
739+
Update: &gnmi.Notification{
740+
Timestamp: 1589476296083000000,
741+
Update: []*gnmi.Update{
742+
{
743+
Path: &gnmi.Path{
744+
Origin: "",
745+
Elem: []*gnmi.PathElem{
746+
{Name: "state"},
747+
{Name: "dummyfield"},
748+
},
749+
},
750+
Val: &gnmi.TypedValue{
751+
Value: &gnmi.TypedValue_StringVal{StringVal: "dummyval"},
752+
},
753+
},
754+
},
755+
},
756+
},
757+
},
758+
},
759+
{
760+
name: "rsp-check-juniper-header-with-subscribed-path",
761+
expectedMeasurementName: hdrInputExtHeaderWithSubscribedPath.SubscribedPath,
762+
err: false,
763+
jctx: &JCtx{
764+
config: Config{
765+
Host: "127.0.0.1",
766+
Port: 32767,
767+
Log: LogConfig{
768+
Verbose: true,
769+
},
770+
},
771+
},
772+
parseOutput: &gnmiParseOutputT{
773+
kvpairs: map[string]string{},
774+
xpaths: map[string]interface{}{},
775+
},
776+
rsp: &gnmi.SubscribeResponse{
777+
Extension: []*gnmi_ext1.Extension{
778+
{
779+
Ext: &gnmi_ext1.Extension_RegisteredExt{
780+
RegisteredExt: &gnmi_ext1.RegisteredExtension{
781+
Id: gnmi_ext1.ExtensionID_EID_JUNIPER_TELEMETRY_HEADER,
782+
Msg: hdrInputExtHeaderWithSubscribedPathBytes,
783+
},
784+
},
785+
},
786+
},
787+
Response: &gnmi.SubscribeResponse_Update{
788+
Update: &gnmi.Notification{
789+
Timestamp: 1589476296083000000,
790+
Update: []*gnmi.Update{
791+
{
792+
Path: &gnmi.Path{
793+
Origin: "",
794+
Elem: []*gnmi.PathElem{
795+
{Name: "state"},
796+
{Name: "dummyfield"},
797+
},
798+
},
799+
Val: &gnmi.TypedValue{
800+
Value: &gnmi.TypedValue_StringVal{StringVal: "dummyval"},
801+
},
802+
},
803+
},
804+
},
805+
},
806+
},
807+
},
808+
}
809+
810+
for _, test := range tests {
811+
t.Run(test.name, func(t *testing.T) {
812+
parseOutput, err := gnmiParseNotification(false, test.rsp, test.parseOutput, true)
813+
if err != nil && strings.Contains(err.Error(), gGnmiJtimonIgnoreErrorSubstr) {
814+
err = nil
815+
}
816+
if err != nil {
817+
errMsg := fmt.Sprintf("didn't expect error:%v", err)
818+
t.Errorf(errMsg)
819+
}
820+
821+
parseOutput, err = gnmiParseHeader(test.rsp, parseOutput)
822+
if !test.err {
823+
if err != nil && strings.Contains(err.Error(), gGnmiJtimonIgnoreErrorSubstr) {
824+
err = nil
825+
}
826+
if err != nil {
827+
errMsg := fmt.Sprintf("didn't expect error:%v", err)
828+
t.Errorf(errMsg)
829+
}
830+
if parseOutput.mName != test.expectedMeasurementName {
831+
errMsg := fmt.Sprintf("Measurement name, expected: %v, got: %v",
832+
test.expectedMeasurementName, parseOutput.mName)
833+
t.Errorf(errMsg)
834+
}
835+
}
836+
837+
if test.err {
838+
if err == nil {
839+
errMsg := "expected error"
840+
t.Errorf(errMsg)
841+
}
842+
}
843+
})
844+
}
845+
846+
*noppgoroutines = false
847+
*prom = false
848+
gGnmiUnitTestCoverage = false
849+
}
850+
620851
// For the below function, better change jtisim?
621852
func TestSubscribegNMI(t *testing.T) {
622853
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"host": "127.0.0.1",
3+
"port": 50051,
4+
"cid": "my-client-id",
5+
"influx" : {
6+
"server" : "127.0.0.1",
7+
"port" : 8086,
8+
"dbname" : "db",
9+
"measurement" : "m",
10+
"user" : "influx",
11+
"password" : "influxdb"
12+
},
13+
"log" : {
14+
"file" : "/tmp/jtisim.log"
15+
},
16+
"internal-jtimon": {
17+
"data-log-file": "tmp/only_packet_dumps"
18+
},
19+
"paths": [{
20+
"path": "/interfaces",
21+
"freq": 2000
22+
}]
23+
}

0 commit comments

Comments
 (0)