@@ -2,7 +2,9 @@ package model
22
33import (
44 "encoding/json"
5+ "strings"
56 "testing"
7+ "time"
68
79 "github.com/netobserv/network-observability-console-plugin/pkg/utils/constants"
810 "github.com/stretchr/testify/assert"
@@ -34,6 +36,57 @@ func TestQueryResponseUnmarshal(t *testing.T) {
3436 assert .IsType (t , expType , qr .Data .Result )
3537}
3638
39+ func TestQueryResponseUnmarshalLineMapping (t * testing.T ) {
40+ AddFlowLineMapping (func (in string ) string {
41+ return strings .ReplaceAll (in , "Bytes" , "Bytezz" )
42+ })
43+ js := `
44+ {
45+ "status": "success",
46+ "data": {
47+ "resultType": "streams",
48+ "result": [
49+ {
50+ "stream": {
51+ "app": "netobserv-flowcollector"
52+ },
53+ "values": [
54+ [
55+ "1731926700000000000",
56+ "{\"SrcK8S_Name\":\"ip-10-0-1-7.ec2.internal\",\"Bytes\":66,\"Packets\":1,\"Interfaces\":[\"br-ex\"]}"
57+ ]
58+ ]
59+ }
60+ ],
61+ "stats": {
62+ "summary": {}
63+ }
64+ }
65+ }
66+ `
67+
68+ var qr QueryResponse
69+ err := json .Unmarshal ([]byte (js ), & qr )
70+ require .NoError (t , err )
71+ assert .Equal (t , ResultTypeStream , string (qr .Data .ResultType ))
72+ assert .NotNil (t , qr .Data .Result )
73+ var expType Streams
74+ assert .IsType (t , expType , qr .Data .Result )
75+ data := qr .Data .Result .(Streams )
76+ assert .Len (t , data , 1 )
77+ assert .Equal (t , Stream {
78+ Labels : map [string ]string {
79+ "app" : "netobserv-flowcollector" ,
80+ },
81+ Entries : []Entry {
82+ {
83+ Timestamp : time .Date (2024 , time .November , 18 , 11 , 45 , 0 , 0 , time .Local ),
84+ Line : `{"SrcK8S_Name":"ip-10-0-1-7.ec2.internal","Bytezz":66,"Packets":1,"Interfaces":["br-ex"]}` ,
85+ },
86+ },
87+ }, data [0 ])
88+ }
89+
3790func TestAggregatedQueryResponseMarshal (t * testing.T ) {
3891 qr := AggregatedQueryResponse {
3992 ResultType : ResultTypeStream ,
0 commit comments