@@ -69,10 +69,12 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
6969
7070 thingId := "91f30213-2bd7-480a-b1dc-f31b01840e7e"
7171 propertyId := "c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac"
72+ propertyStringId := "a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb"
7273
7374 // Init client
7475 iotcl := iotMocks .NewAPI (t )
7576
77+ // Time series data extraction mock
7678 now := time .Now ()
7779 responses := []iotclient.ArduinoSeriesResponse {
7880 {
@@ -88,9 +90,23 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
8890 }
8991 iotcl .On ("GetTimeSeriesByThing" , ctx , thingId , mock .Anything , mock .Anything , int64 (300 ), "AVG" ).Return (& samples , false , nil )
9092
93+ // Time series sampling mock
94+ sampledResponse := []iotclient.ArduinoSeriesSampledResponse {
95+ {
96+ Query : fmt .Sprintf ("property.%s" , propertyStringId ),
97+ Times : []time.Time {now .Add (- time .Minute * 2 ), now .Add (- time .Minute * 1 ), now },
98+ Values : []any {"a" , "b" , "c" },
99+ CountValues : 3 ,
100+ },
101+ }
102+ samplesSampled := iotclient.ArduinoSeriesBatchSampled {
103+ Responses : sampledResponse ,
104+ }
105+ iotcl .On ("GetTimeSeriesStringSampling" , ctx , []string {propertyStringId }, mock .Anything , mock .Anything , int32 (300 )).Return (& samplesSampled , false , nil )
106+
91107 tsextractorClient := New (iotcl , logger )
92108
93- propCount := int64 (1 )
109+ propCount := int64 (2 )
94110 thingsMap := make (map [string ]iotclient.ArduinoThing )
95111 thingsMap [thingId ] = iotclient.ArduinoThing {
96112 Id : thingId ,
@@ -101,6 +117,11 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
101117 Id : propertyId ,
102118 Type : "FLOAT" ,
103119 },
120+ {
121+ Name : "pstringVar" ,
122+ Id : propertyStringId ,
123+ Type : "CHARSTRING" ,
124+ },
104125 },
105126 PropertiesCount : & propCount ,
106127 }
@@ -118,13 +139,101 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
118139 defer outF .Close ()
119140 content , err := io .ReadAll (outF )
120141 assert .NoError (t , err )
142+
143+ t .Log (string (content ))
144+
121145 entries := []string {
122- "timestamp,thing_id,thing_name,property_id,property_name,property_type,value" ,
146+ "timestamp,thing_id,thing_name,property_id,property_name,property_type,value,aggregation_statistic " ,
123147 "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac,ptest,FLOAT,1,AVG" ,
124148 "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac,ptest,FLOAT,2,AVG" ,
149+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb,pstringVar,CHARSTRING,a," ,
150+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb,pstringVar,CHARSTRING,b," ,
151+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb,pstringVar,CHARSTRING,c," ,
152+ }
153+ for _ , entry := range entries {
154+ assert .Contains (t , string (content ), entry )
155+ }
156+ }
157+
158+ func TestExtractionFlow_rawResolution (t * testing.T ) {
159+ logger := logrus .NewEntry (logrus .New ())
160+ ctx := context .Background ()
161+
162+ thingId := "91f30213-2bd7-480a-b1dc-f31b01840e7e"
163+ propertyId := "c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac"
164+ propertyStringId := "a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb"
165+
166+ // Init client
167+ iotcl := iotMocks .NewAPI (t )
168+
169+ // Time series data extraction mock
170+ now := time .Now ()
171+ responses := []iotclient.ArduinoSeriesRawResponse {
172+ {
173+ Query : fmt .Sprintf ("property.%s" , propertyId ),
174+ Times : []time.Time {now .Add (- time .Minute * 1 ), now },
175+ Values : []any {1.0 , 2.0 },
176+ CountValues : 2 ,
177+ },
178+ {
179+ Query : fmt .Sprintf ("property.%s" , propertyStringId ),
180+ Times : []time.Time {now .Add (- time .Minute * 2 ), now .Add (- time .Minute * 1 ), now },
181+ Values : []any {"a" , "b" , "c" },
182+ CountValues : 3 ,
183+ },
184+ }
185+ samples := iotclient.ArduinoSeriesRawBatch {
186+ Responses : responses ,
187+ }
188+ iotcl .On ("GetRawTimeSeriesByThing" , ctx , thingId , mock .Anything , mock .Anything ).Return (& samples , false , nil )
189+
190+ tsextractorClient := New (iotcl , logger )
191+
192+ propCount := int64 (2 )
193+ thingsMap := make (map [string ]iotclient.ArduinoThing )
194+ thingsMap [thingId ] = iotclient.ArduinoThing {
195+ Id : thingId ,
196+ Name : "test" ,
197+ Properties : []iotclient.ArduinoProperty {
198+ {
199+ Name : "ptest" ,
200+ Id : propertyId ,
201+ Type : "FLOAT" ,
202+ },
203+ {
204+ Name : "pstringVar" ,
205+ Id : propertyStringId ,
206+ Type : "CHARSTRING" ,
207+ },
208+ },
209+ PropertiesCount : & propCount ,
210+ }
211+
212+ writer , from , err := tsextractorClient .ExportTSToFile (ctx , 60 , thingsMap , - 1 , "" , false )
213+ assert .NoError (t , err )
214+ assert .NotNil (t , writer )
215+ assert .NotNil (t , from )
216+
217+ writer .Close ()
218+ defer writer .Delete ()
219+
220+ outF , err := os .Open (writer .GetFilePath ())
221+ assert .NoError (t , err )
222+ defer outF .Close ()
223+ content , err := io .ReadAll (outF )
224+ assert .NoError (t , err )
225+
226+ t .Log (string (content ))
227+
228+ entries := []string {
229+ "timestamp,thing_id,thing_name,property_id,property_name,property_type,value" ,
230+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac,ptest,FLOAT,1" ,
231+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac,ptest,FLOAT,2" ,
232+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb,pstringVar,CHARSTRING,a" ,
233+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb,pstringVar,CHARSTRING,b" ,
234+ "91f30213-2bd7-480a-b1dc-f31b01840e7e,test,a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb,pstringVar,CHARSTRING,c" ,
125235 }
126236 for _ , entry := range entries {
127237 assert .Contains (t , string (content ), entry )
128238 }
129- fmt .Println (string (content ))
130239}
0 commit comments