44 "context"
55 "encoding/json"
66 "testing"
7+ "time"
78
89 "github.com/NeedleInAJayStack/haystack"
910 "github.com/google/go-cmp/cmp"
@@ -12,13 +13,13 @@ import (
1213)
1314
1415func TestQueryData_Eval (t * testing.T ) {
15- evalResponse := haystack .NewGridBuilder ()
16- evalResponse .AddCol ("a" , map [string ]haystack.Val {})
17- evalResponse .AddCol ("b" , map [string ]haystack.Val {})
18- evalResponse .AddRow ([]haystack.Val {haystack .NewStr ("a" ), haystack .NewStr ("b" )})
16+ response := haystack .NewGridBuilder ()
17+ response .AddCol ("a" , map [string ]haystack.Val {})
18+ response .AddCol ("b" , map [string ]haystack.Val {})
19+ response .AddRow ([]haystack.Val {haystack .NewStr ("a" ), haystack .NewStr ("b" )})
1920
2021 client := & testHaystackClient {
21- evalResponse : evalResponse .ToGrid (),
22+ evalResponse : response .ToGrid (),
2223 }
2324
2425 actual := getResponse (
@@ -42,6 +43,75 @@ func TestQueryData_Eval(t *testing.T) {
4243 }
4344}
4445
46+ func TestQueryData_HisRead (t * testing.T ) {
47+ response := haystack .NewGridBuilder ()
48+ response .AddCol ("ts" , map [string ]haystack.Val {})
49+ response .AddCol ("v0" , map [string ]haystack.Val {})
50+ response .AddRow ([]haystack.Val {haystack .NewDateTimeFromGo (time .Unix (0 , 0 )), haystack .NewNumber (5 , "kWh" )})
51+
52+ client := & testHaystackClient {
53+ hisReadResponse : response .ToGrid (),
54+ }
55+
56+ actual := getResponse (
57+ client ,
58+ & QueryModel {
59+ Type : "HisRead" ,
60+ HisRead : "abcdefg-12345678" ,
61+ },
62+ t ,
63+ )
64+
65+ tsVal := time .Unix (0 , 0 )
66+ v0Val := 5.0
67+ expected := data .NewFrame ("" ,
68+ data .NewField ("ts" , nil , []* time.Time {& tsVal }).SetConfig (& data.FieldConfig {DisplayName : "ts" }),
69+ data .NewField ("v0" , nil , []* float64 {& v0Val }).SetConfig (& data.FieldConfig {DisplayName : "v0" }),
70+ )
71+
72+ if ! cmp .Equal (actual , expected , data .FrameTestCompareOptions ()... ) {
73+ t .Error (cmp .Diff (actual , expected , data .FrameTestCompareOptions ()... ))
74+ }
75+ }
76+
77+ func TestQueryData_Read (t * testing.T ) {
78+ response := haystack .NewGridBuilder ()
79+ response .AddCol ("id" , map [string ]haystack.Val {})
80+ response .AddCol ("dis" , map [string ]haystack.Val {})
81+ response .AddCol ("ahu" , map [string ]haystack.Val {})
82+ response .AddRow ([]haystack.Val {
83+ haystack .NewRef ("abcdefg-12345678" , "AHU-1" ),
84+ haystack .NewStr ("AHU-1" ),
85+ haystack .NewMarker (),
86+ })
87+
88+ client := & testHaystackClient {
89+ readResponse : response .ToGrid (),
90+ }
91+
92+ actual := getResponse (
93+ client ,
94+ & QueryModel {
95+ Type : "Read" ,
96+ Read : "ahu" ,
97+ },
98+ t ,
99+ )
100+
101+ idVal := "@abcdefg-12345678 \" AHU-1\" "
102+ disVal := "AHU-1"
103+ ahuVal := "M"
104+ expected := data .NewFrame ("" ,
105+ data .NewField ("id" , nil , []* string {& idVal }).SetConfig (& data.FieldConfig {DisplayName : "id" }),
106+ data .NewField ("dis" , nil , []* string {& disVal }).SetConfig (& data.FieldConfig {DisplayName : "dis" }),
107+ data .NewField ("ahu" , nil , []* string {& ahuVal }).SetConfig (& data.FieldConfig {DisplayName : "ahu" }),
108+ )
109+
110+ if ! cmp .Equal (actual , expected , data .FrameTestCompareOptions ()... ) {
111+ t .Error (cmp .Diff (actual , expected , data .FrameTestCompareOptions ()... ))
112+ }
113+ }
114+
45115func getResponse (
46116 client HaystackClient ,
47117 queryModel * QueryModel ,
0 commit comments