@@ -69,10 +69,12 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
69
69
70
70
thingId := "91f30213-2bd7-480a-b1dc-f31b01840e7e"
71
71
propertyId := "c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac"
72
+ propertyStringId := "a86f4ed9-7f52-4bd3-bdc6-b2936bec68bb"
72
73
73
74
// Init client
74
75
iotcl := iotMocks .NewAPI (t )
75
76
77
+ // Time series data extraction mock
76
78
now := time .Now ()
77
79
responses := []iotclient.ArduinoSeriesResponse {
78
80
{
@@ -88,9 +90,23 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
88
90
}
89
91
iotcl .On ("GetTimeSeriesByThing" , ctx , thingId , mock .Anything , mock .Anything , int64 (300 ), "AVG" ).Return (& samples , false , nil )
90
92
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
+
91
107
tsextractorClient := New (iotcl , logger )
92
108
93
- propCount := int64 (1 )
109
+ propCount := int64 (2 )
94
110
thingsMap := make (map [string ]iotclient.ArduinoThing )
95
111
thingsMap [thingId ] = iotclient.ArduinoThing {
96
112
Id : thingId ,
@@ -101,6 +117,11 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
101
117
Id : propertyId ,
102
118
Type : "FLOAT" ,
103
119
},
120
+ {
121
+ Name : "pstringVar" ,
122
+ Id : propertyStringId ,
123
+ Type : "CHARSTRING" ,
124
+ },
104
125
},
105
126
PropertiesCount : & propCount ,
106
127
}
@@ -118,13 +139,101 @@ func TestExtractionFlow_defaultAggregation(t *testing.T) {
118
139
defer outF .Close ()
119
140
content , err := io .ReadAll (outF )
120
141
assert .NoError (t , err )
142
+
143
+ t .Log (string (content ))
144
+
121
145
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 " ,
123
147
"91f30213-2bd7-480a-b1dc-f31b01840e7e,test,c86f4ed9-7f52-4bd3-bdc6-b2936bec68ac,ptest,FLOAT,1,AVG" ,
124
148
"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" ,
125
235
}
126
236
for _ , entry := range entries {
127
237
assert .Contains (t , string (content ), entry )
128
238
}
129
- fmt .Println (string (content ))
130
239
}
0 commit comments