-
Notifications
You must be signed in to change notification settings - Fork 12
/
soql_suite_test.go
465 lines (382 loc) · 18.2 KB
/
soql_suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
package soql_test
import (
"testing"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/forcedotcom/go-soql"
)
func TestSoql(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Soql Suite")
}
type TestSoqlStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
}
type TestSoqlMixedDataAndOperatorStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause QueryCriteriaWithMixedDataTypesAndOperators `soql:"whereClause"`
}
type TestQueryCriteria struct {
IncludeNamePattern []string `soql:"likeOperator,fieldName=Host_Name__c"`
Roles []string `soql:"inOperator,fieldName=Role__r.Name"`
ExcludeNamePattern []string `soql:"notLikeOperator,fieldName=Host_Name__c"`
AssetType string `soql:"equalsOperator,fieldName=Tech_Asset__r.Asset_Type_Asset_Type__c"`
Status string `soql:"notEqualsOperator,fieldName=Status__c"`
AllowNullLastDiscoveredDate *bool `soql:"nullOperator,fieldName=Last_Discovered_Date__c"`
ExcludeIDs []string `soql:"notInOperator,fieldName=id"`
}
type NonSoqlStruct struct {
Key string
Value string
}
type NonNestedStruct struct {
Name string `soql:"selectColumn,fieldName=Name"`
SomeValue string `soql:"selectColumn,fieldName=SomeValue__c"`
NonSoqlStruct NonSoqlStruct
}
type NestedStruct struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
NonNestedStruct NonNestedStruct `soql:"selectColumn,fieldName=NonNestedStruct__r"`
}
type TestChildStruct struct {
SelectClause ChildStruct `soql:"selectClause,tableName=SM_Application_Versions__c"`
WhereClause ChildQueryCriteria `soql:"whereClause"`
}
type TestChildWithOrderByStruct struct {
SelectClause ChildStruct `soql:"selectClause,tableName=SM_Application_Versions__c"`
OrderByClause []Order `soql:"orderByClause"`
}
type ChildStruct struct {
Version string `soql:"selectColumn,fieldName=Version__c"`
}
type ChildQueryCriteria struct {
Name string `soql:"equalsOperator,fieldName=Name__c"`
}
type ParentStruct struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
NonNestedStruct NonNestedStruct `soql:"selectColumn,fieldName=NonNestedStruct__r"`
ChildStruct TestChildStruct `soql:"selectChild,fieldName=Application_Versions__r"`
SomeNonSoqlMember string `json:"some_nonsoql_member"`
}
type OrderByParentStruct struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
ChildStruct TestChildWithOrderByStruct `soql:"selectChild,fieldName=Application_Versions__r"`
}
type DefaultFieldNameParentStruct struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
NonNestedStruct NonNestedStruct `soql:"selectColumn,fieldName=NonNestedStruct__r"`
ChildStruct TestChildStruct `soql:"selectChild"`
SomeNonSoqlMember string `json:"some_nonsoql_member"`
}
type InvalidTestChildStruct struct {
WhereClause ChildQueryCriteria `soql:"whereClause"`
}
type InvalidParentStruct struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
ChildStruct InvalidTestChildStruct `soql:"selectChild,fieldName=Application_Versions__r"`
}
type InvalidSelectChildClause struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
ChildStruct int `soql:"selectChild,fieldName=Application_Versions__r"`
}
type ChildTagToNonStruct struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
ChildStruct string `soql:"selectChild,fieldName=Application_Versions__r"`
}
type MultipleSelectClause struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
ParentStruct ParentStruct `soql:"selectClause,tableName=SM_Table__c"`
}
type MultipleWhereClause struct {
WhereClause1 ChildQueryCriteria `soql:"whereClause"`
WhereClause2 ChildQueryCriteria `soql:"whereClause"`
}
type MultipleOrderByClause struct {
OrderByClause1 []Order `soql:"orderByClause"`
OrderByClause2 []Order `soql:"orderByClause"`
}
type OnlyWhereClause struct {
WhereClause TestQueryCriteria `soql:"whereClause"`
}
type OnlyOrderByClause struct {
OrderByClause []Order `soql:"orderByClause"`
}
type EmptyStruct struct {
}
type InvalidTagInStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause ChildQueryCriteria `soql:"whereClause"`
AnotherMember NestedStruct `soql:"invalidClause,tableName=SM_Logical_Host__c"`
}
type DefaultFieldNameStruct struct {
DefaultName string `soql:"selectColumn"`
Description string `soql:"selectColumn,fieldName=Description__c"`
}
type DefaultTableNameStruct struct {
SomeTableName NestedStruct `soql:"selectClause"`
WhereClause TestQueryCriteria `soql:"whereClause"`
}
type DefaultFieldNameQueryCriteria struct {
IncludeNamePattern []string `soql:"likeOperator,fieldName=Host_Name__c"`
Role []string `soql:"inOperator"`
}
type QueryCriteriaWithIntegerTypes struct {
NumOfCPUCores int `soql:"equalsOperator,fieldName=Num_of_CPU_Cores__c"`
PhysicalCPUCount int8 `soql:"equalsOperator,fieldName=Physical_CPU_Count__c"`
NumOfSuccessivePuppetRunFailures int16 `soql:"equalsOperator,fieldName=Number_Of_Successive_Puppet_Run_Failures__c"`
NumOfCoolanLogFiles int32 `soql:"equalsOperator,fieldName=Num_Of_Coolan_Log_Files__c"`
PvtTestFailCount int64 `soql:"equalsOperator,fieldName=Pvt_Test_Fail_Count__c"`
}
type QueryCriteriaWithUnsignedIntegerTypes struct {
NumOfCPUCores uint `soql:"equalsOperator,fieldName=Num_of_CPU_Cores__c"`
PhysicalCPUCount uint8 `soql:"equalsOperator,fieldName=Physical_CPU_Count__c"`
NumOfSuccessivePuppetRunFailures uint16 `soql:"equalsOperator,fieldName=Number_Of_Successive_Puppet_Run_Failures__c"`
NumOfCoolanLogFiles uint32 `soql:"equalsOperator,fieldName=Num_Of_Coolan_Log_Files__c"`
PvtTestFailCount uint64 `soql:"equalsOperator,fieldName=Pvt_Test_Fail_Count__c"`
}
type QueryCriteriaWithFloatTypes struct {
NumOfCPUCores float32 `soql:"equalsOperator,fieldName=Num_of_CPU_Cores__c"`
PhysicalCPUCount float64 `soql:"equalsOperator,fieldName=Physical_CPU_Count__c"`
}
type QueryCriteriaWithFloatPtrTypes struct {
NumOfCPUCores *float64 `soql:"equalsOperator,fieldName=Num_of_CPU_Cores__c"`
PhysicalCPUCount *float64 `soql:"equalsOperator,fieldName=Physical_CPU_Count__c"`
}
type QueryCriteriaWithBooleanType struct {
NUMAEnabled bool `soql:"equalsOperator,fieldName=NUMA_Enabled__c"`
DisableAlerts bool `soql:"equalsOperator,fieldName=Disable_Alerts__c"`
}
type QueryCriteriaWithNoSoqlTag struct {
NUMAEnabled bool `soql:"equalsOperator,fieldName=NUMA_Enabled__c"`
DisableAlerts bool `json:"random_value"`
}
type QueryCriteriaWithBooleanPtrType struct {
NUMAEnabled *bool `soql:"equalsOperator,fieldName=NUMA_Enabled__c"`
DisableAlerts *bool `soql:"equalsOperator,fieldName=Disable_Alerts__c"`
}
type QueryCriteriaWithDateTimeType struct {
CreatedDate time.Time `soql:"equalsOperator,fieldName=CreatedDate"`
}
type QueryCriteriaWithPtrDateTimeType struct {
CreatedDate *time.Time `soql:"equalsOperator,fieldName=CreatedDate"`
ResolvedDate *time.Time `soql:"equalsOperator,fieldName=ResolvedDate"`
}
type QueryCriteriaNumericComparisonOperators struct {
NumOfCPUCores int `soql:"greaterThanOperator,fieldName=Num_of_CPU_Cores__c"`
PhysicalCPUCount int `soql:"lessThanOperator,fieldName=Physical_CPU_Count__c"`
NumOfSuccessivePuppetRunFailures int `soql:"greaterThanOrEqualsToOperator,fieldName=Number_Of_Successive_Puppet_Run_Failures__c"`
NumOfCoolanLogFiles int `soql:"lessThanOrEqualsToOperator,fieldName=Num_Of_Coolan_Log_Files__c"`
}
type QueryCriteriaDateLiteralsOperatorsInt struct {
CreatedDate int `soql:"greaterNextNDaysOperator,fieldName=CreatedDate"`
ClosedDate int `soql:"lessNextNDaysOperator,fieldName=ClosedDate"`
}
type QueryCriteriaDateLiteralsOperatorsUint struct {
CreatedDate uint `soql:"greaterNextNDaysOperator,fieldName=CreatedDate"`
ClosedDate uint `soql:"lessNextNDaysOperator,fieldName=ClosedDate"`
}
type QueryCriteriaDateLiteralsOperatorsPtr struct {
CreatedDate *int `soql:"greaterNextNDaysOperator,fieldName=CreatedDate"`
OtherDate *int `soql:"equalsNextNDaysOperator,fieldName=OtherDate"`
ClosedDate *int `soql:"lessNextNDaysOperator,fieldName=ClosedDate"`
ScheduledDate *int `soql:"lessOrEqualNextNDaysOperator,fieldName=ScheduledDate"`
DeliveredDate *int `soql:"greaterOrEqualNextNDaysOperator,fieldName=DeliveredDate"`
}
type QueryCriteriaDateLastNDaysLiteralsOperatorsPtr struct {
CreatedDate *int `soql:"greaterLastNDaysOperator,fieldName=CreatedDate"`
OtherDate *int `soql:"equalsLastNDaysOperator,fieldName=OtherDate"`
ClosedDate *int `soql:"lessLastNDaysOperator,fieldName=ClosedDate"`
ScheduledDate *int `soql:"lessOrEqualLastNDaysOperator,fieldName=ScheduledDate"`
DeliveredDate *int `soql:"greaterOrEqualLastNDaysOperator,fieldName=DeliveredDate"`
}
var TestDateFormat = "2006-01-02"
type QueryCriteriaWithMixedDataTypesAndOperators struct {
BIOSType string `soql:"equalsOperator,fieldName=BIOS_Type__c"`
NumOfCPUCores int `soql:"greaterThanOperator,fieldName=Num_of_CPU_Cores__c"`
NUMAEnabled bool `soql:"equalsOperator,fieldName=NUMA_Enabled__c"`
PvtTestFailCount int64 `soql:"lessThanOrEqualsToOperator,fieldName=Pvt_Test_Fail_Count__c"`
PhysicalCPUCount uint8 `soql:"greaterThanOrEqualsToOperator,fieldName=Physical_CPU_Count__c"`
CreatedDate time.Time `soql:"equalsOperator,fieldName=CreatedDate,format=2006-01-02"`
UpdatedDate *time.Time `soql:"equalsOperator,fieldName=UpdatedDate,format=2006-01-02"`
DisableAlerts bool `soql:"equalsOperator,fieldName=Disable_Alerts__c"`
AllocationLatency float64 `soql:"lessThanOperator,fieldName=Allocation_Latency__c"`
MajorOSVersion string `soql:"equalsOperator,fieldName=Major_OS_Version__c"`
NumOfSuccessivePuppetRunFailures uint32 `soql:"equalsOperator,fieldName=Number_Of_Successive_Puppet_Run_Failures__c"`
LastRestart time.Time `soql:"greaterThanOperator,fieldName=Last_Restart__c"`
Memory *float64 `soql:"equalsOperator,fieldName=Memory__c"`
NumHardDrives *int `soql:"equalsOperator,fieldName=NumHardDrives__c"`
ClosedDate int `soql:"greaterNextNDaysOperator,fieldName=ClosedDate"`
}
type InvalidSelectClause struct {
SelectClause string `soql:"selectClause,tableName=SM_Logical_Host__c"`
}
type TestSoqlOrderByStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
OrderByClause []Order `soql:"orderByClause"`
}
type TestSoqlChildRelationOrderByStruct struct {
SelectClause OrderByParentStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
OrderByClause []Order `soql:"orderByClause"`
}
type TestSoqlLimitStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
Limit *int `soql:"limitClause"`
}
type TestSoqlInvalidLimitStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
Limit string `soql:"limitClause"`
}
type TestSoqlMultipleLimitStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
Limit *int `soql:"limitClause"`
AlsoLimit *int `soql:"limitClause"`
}
type ParentLimitStruct struct {
ID string `soql:"selectColumn,fieldName=Id"`
Name string `soql:"selectColumn,fieldName=Name__c"`
ChildStruct ChildLimitStruct `soql:"selectChild,fieldName=Application_Versions__r"`
}
type ChildLimitStruct struct {
SelectClause TestChildLimitSelect `soql:"selectClause,tableName=Application_Versions__c"`
Limit *int `soql:"limitClause"`
}
type TestChildLimitSelect struct {
ID string `soql:"selectColumn,fieldName=Id"`
Version string `soql:"selectColumn,fieldName=Version__c"`
}
type TestSoqlChildRelationLimitStruct struct {
SelectClause ParentLimitStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
Limit *int `soql:"limitClause"`
}
type TestSoqlOffsetStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
Offset *int `soql:"offsetClause"`
}
type TestSoqlInvalidOffsetStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
Offset string `soql:"offsetClause"`
}
type TestSoqlMultipleOffsetStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
Offset *int `soql:"offsetClause"`
AlsoOffset *int `soql:"offsetClause"`
}
type TestSoqlLimitAndOffsetStruct struct {
SelectClause NestedStruct `soql:"selectClause,tableName=SM_Logical_Host__c"`
WhereClause TestQueryCriteria `soql:"whereClause"`
Limit *int `soql:"limitClause"`
Offset *int `soql:"offsetClause"`
}
// setups for OR and subfilter tests
type orSOQLQuery struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause positionOrDeptCriteria `soql:"whereClause,joiner=OR"`
}
type orLowerSOQLQuery struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause positionOrDeptCriteria `soql:"whereClause,joiner=or"`
}
type andSOQLQuery struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause positionOrDeptCriteria `soql:"whereClause,joiner=AND"`
}
type invalidJoinerSOQLQuery struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause positionOrDeptCriteria `soql:"whereClause,joiner=not-a-real-value"`
}
type noJoinerSOQLQuery struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause positionOrDeptCriteria `soql:"whereClause"`
}
type positionOrDeptCriteria struct {
Title string `soql:"equalsOperator,fieldName=Title"`
Department string `soql:"equalsOperator,fieldName=Department"`
}
type contact struct {
Name string `soql:"selectColumn,fieldName=Name" json:"Name"`
Email string `soql:"selectColumn,fieldName=Email" json:"Email"`
Phone string `soql:"selectColumn,fieldName=Phone" json:"Phone"`
}
type queryCriteria struct {
Position positionCriteria `soql:"subquery,joiner=OR"`
Contactable contactableCriteria `soql:"subquery,joiner=OR"`
}
type contactableCriteria struct {
EmailOK emailCheck `soql:"subquery,joiner=and"`
PhoneOK phoneCheck `soql:"subquery,joiner=and"`
}
type emailCheck struct {
Email bool `soql:"nullOperator,fieldName=Email"`
EmailOptedOut bool `soql:"equalsOperator,fieldName=HasOptedOutOfEmail"`
}
type phoneCheck struct {
Phone bool `soql:"nullOperator,fieldName=Phone"`
DoNotCall bool `soql:"equalsOperator,fieldName=DoNotCall"`
}
type positionCriteria struct {
Title string `soql:"equalsOperator,fieldName=Title"`
DepartmentManager deptManagerCriteria `soql:"subquery"`
}
type deptManagerCriteria struct {
Department string `soql:"equalsOperator,fieldName=Department"`
Title []string `soql:"likeOperator,fieldName=Title"`
}
type soqlSubQueryTestStruct struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause queryCriteria `soql:"whereClause"`
}
type soqlSubQueryInvalidTypeTestStruct struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause invalidSubqueryCriteria `soql:"whereClause"`
}
type invalidSubqueryCriteria struct {
Position string `soql:"subquery,joiner=OR"`
Contactable contactableCriteria `soql:"subquery,joiner=OR"`
}
type soqlSubQueryPtrTestStruct struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause ptrSubqueryCriteria `soql:"whereClause"`
}
type ptrSubqueryCriteria struct {
Position *positionCriteria `soql:"subquery,joiner=OR"`
Contactable *contactableCriteria `soql:"subquery,joiner=OR"`
}
type soqlSubQueryInTestStruct struct {
SelectClause contact `soql:"selectClause,tableName=Contact"`
WhereClause inSubqueryCriteria `soql:"whereClause"`
}
type inSubqueryCriteria struct {
Type string `soql:"equalsOperator,fieldName=Type"`
NotInFraudTable *soqlFraudStruct `soql:"subquery,joiner=NOT IN,fieldName=Name"`
InFraudTable *soqlFraudStruct `soql:"subquery,joiner=IN,fieldName=Name"`
InFraudTableWithoutFieldName *soqlFraudStruct `soql:"subquery,joiner=IN"`
Country string `soql:"equalsOperator,fieldName=Country"`
}
type fraudCriteria struct {
IsFraud bool `soql:"equalsOperator,fieldName=isFraud"`
}
type soqlFraudStruct struct {
SelectClause contact `soql:"selectClause,tableName=Fraud"`
WhereClause fraudCriteria `soql:"whereClause"`
}