Skip to content

Commit c956713

Browse files
author
Feng Shang
committed
test(ut): clear test
1 parent c9a2620 commit c956713

File tree

1 file changed

+81
-71
lines changed

1 file changed

+81
-71
lines changed

src/test/groovy/com/featureprobe/sdk/server/ConditionSpec.groovy

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class ConditionSpec extends Specification {
2727
condition.setObjects(["12345", "987654", "665544", "13797347245"])
2828
condition.setPredicate(PredicateType.IS_ONE_OF)
2929
user.with("userId", "12345")
30-
def hitSuccess = condition.matchObjects(user, segments)
30+
def hitSuccess = condition.matchObjects(user, [:])
3131
user.with("userId", "999999")
32-
def hitMiss1 = condition.matchObjects(user, segments)
32+
def hitMiss1 = condition.matchObjects(user, [:])
3333
user.with("userId", "\t \n ")
34-
def hitMiss2 = condition.matchObjects(user, segments)
34+
def hitMiss2 = condition.matchObjects(user, [:])
3535

3636
then:
3737
hitSuccess
@@ -44,11 +44,11 @@ class ConditionSpec extends Specification {
4444
condition.setObjects(["123", "888"])
4545
condition.setPredicate(PredicateType.ENDS_WITH)
4646
user.with("userId", "123123")
47-
def hitSuccess = condition.matchObjects(user, segments)
47+
def hitSuccess = condition.matchObjects(user, [:])
4848
user.with("userId", "999999")
49-
def hitMiss1 = condition.matchObjects(user, segments)
49+
def hitMiss1 = condition.matchObjects(user, [:])
5050
user.with("userId", null)
51-
def hitMiss2 = condition.matchObjects(user, segments)
51+
def hitMiss2 = condition.matchObjects(user, [:])
5252

5353
then:
5454
hitSuccess
@@ -61,9 +61,9 @@ class ConditionSpec extends Specification {
6161
condition.setObjects(["123"])
6262
condition.setPredicate(PredicateType.STARTS_WITH)
6363
user.with("userId", "123321")
64-
def hitSuccess = condition.matchObjects(user, segments)
64+
def hitSuccess = condition.matchObjects(user, [:])
6565
user.with("userId", "3333")
66-
def hitMiss = condition.matchObjects(user, segments)
66+
def hitMiss = condition.matchObjects(user, [:])
6767

6868
then:
6969
hitSuccess
@@ -75,9 +75,9 @@ class ConditionSpec extends Specification {
7575
condition.setObjects(["123", "456"])
7676
condition.setPredicate(PredicateType.CONTAINS)
7777
user.with("userId", "456433")
78-
def hitSuccess = condition.matchObjects(user, segments)
78+
def hitSuccess = condition.matchObjects(user, [:])
7979
user.with("userId", "999999")
80-
def hitMiss = condition.matchObjects(user, segments)
80+
def hitMiss = condition.matchObjects(user, [:])
8181

8282
then:
8383
hitSuccess
@@ -89,9 +89,9 @@ class ConditionSpec extends Specification {
8989
condition.setObjects(["0?(13|14|15|18)[0-9]{9}"])
9090
condition.setPredicate(PredicateType.MATCHES_REGEX)
9191
user.with("userId", "13797347245")
92-
def hitSuccess = condition.matchObjects(user, segments)
92+
def hitSuccess = condition.matchObjects(user, [:])
9393
user.with("userId", "122122")
94-
def hitMiss = condition.matchObjects(user, segments)
94+
def hitMiss = condition.matchObjects(user, [:])
9595

9696
then:
9797
hitSuccess
@@ -103,9 +103,9 @@ class ConditionSpec extends Specification {
103103
condition.setObjects(["\\\\\\"])
104104
user.with("userId", "13797347245")
105105
condition.setPredicate(PredicateType.MATCHES_REGEX)
106-
def hitMiss = condition.matchObjects(user, segments)
106+
def hitMiss = condition.matchObjects(user, [:])
107107
condition.setPredicate(PredicateType.DOES_NOT_MATCH_REGEX)
108-
def hitMiss2 = condition.matchObjects(user, segments)
108+
def hitMiss2 = condition.matchObjects(user, [:])
109109

110110
then:
111111
!hitMiss
@@ -117,9 +117,9 @@ class ConditionSpec extends Specification {
117117
condition.setObjects(["12345", "987654", "665544"])
118118
condition.setPredicate(PredicateType.IS_NOT_ANY_OF)
119119
user.with("userId", "999999999")
120-
def hitSuccess = condition.matchObjects(user, segments)
120+
def hitSuccess = condition.matchObjects(user, [:])
121121
user.with("userId", "12345")
122-
def hitMiss = condition.matchObjects(user, segments)
122+
def hitMiss = condition.matchObjects(user, [:])
123123

124124
then:
125125
hitSuccess
@@ -131,9 +131,9 @@ class ConditionSpec extends Specification {
131131
condition.setObjects(["123", "456"])
132132
condition.setPredicate(PredicateType.DOES_NOT_END_WITH)
133133
user.with("userId", "3333333")
134-
def hitSuccess = condition.matchObjects(user, segments)
134+
def hitSuccess = condition.matchObjects(user, [:])
135135
user.with("userId", "456456")
136-
def hitMiss = condition.matchObjects(user, segments)
136+
def hitMiss = condition.matchObjects(user, [:])
137137

138138
then:
139139
hitSuccess
@@ -145,9 +145,9 @@ class ConditionSpec extends Specification {
145145
condition.setObjects(["123", "456"])
146146
condition.setPredicate(PredicateType.DOES_NOT_START_WITH)
147147
user.with("userId", "3333333")
148-
def hitSuccess = condition.matchObjects(user, segments)
148+
def hitSuccess = condition.matchObjects(user, [:])
149149
user.with("userId", "123456")
150-
def hitMiss = condition.matchObjects(user, segments)
150+
def hitMiss = condition.matchObjects(user, [:])
151151

152152
then:
153153
hitSuccess
@@ -159,9 +159,9 @@ class ConditionSpec extends Specification {
159159
condition.setObjects(["12345", "987654", "665544"])
160160
condition.setPredicate(PredicateType.DOES_NOT_CONTAIN)
161161
user.with("userId", "999999999")
162-
def hitSuccess = condition.matchObjects(user, segments)
162+
def hitSuccess = condition.matchObjects(user, [:])
163163
user.with("userId", "12345")
164-
def hitMiss = condition.matchObjects(user, segments)
164+
def hitMiss = condition.matchObjects(user, [:])
165165

166166
then:
167167
hitSuccess
@@ -173,20 +173,25 @@ class ConditionSpec extends Specification {
173173
condition.setObjects(["0?(13|14|15|18)[0-9]{9}"])
174174
condition.setPredicate(PredicateType.DOES_NOT_MATCH_REGEX)
175175
user.with("userId", "2122121")
176-
def hitSuccess = condition.matchObjects(user, segments)
176+
def hitSuccess = condition.matchObjects(user, [:])
177177
user.with("userId", "13797347245")
178-
def hitMiss = condition.matchObjects(user, segments)
178+
def hitMiss = condition.matchObjects(user, [:])
179179

180180
then:
181181
hitSuccess
182182
!hitMiss
183183
}
184184

185185
def "[is in] segment condition match"() {
186-
when:
186+
given:
187+
segments = ["test_project\$test_segment": new Segment(uniqueId: "test_project\$test_segment", version: 1,
188+
rules: [new SegmentRule(conditions: [new Condition(type: ConditionType.STRING, subject: "userId",
189+
predicate: PredicateType.IS_ONE_OF, objects: ["1", "2"])])])]
187190
condition.setType(ConditionType.SEGMENT)
188191
condition.setObjects(["test_project\$test_segment"])
189192
condition.setPredicate(PredicateType.IS_IN)
193+
194+
when:
190195
user.with("userId", "1")
191196
def hitSuccess = condition.matchObjects(user, segments)
192197
user.with("userId", "3")
@@ -198,10 +203,15 @@ class ConditionSpec extends Specification {
198203
}
199204

200205
def "[is not in] segment condition match"() {
201-
when:
206+
given:
207+
segments = ["test_project\$test_segment": new Segment(uniqueId: "test_project\$test_segment", version: 1,
208+
rules: [new SegmentRule(conditions: [new Condition(type: ConditionType.STRING, subject: "userId",
209+
predicate: PredicateType.IS_ONE_OF, objects: ["1", "2"])])])]
202210
condition.setType(ConditionType.SEGMENT)
203211
condition.setObjects(["test_project\$test_segment"])
204212
condition.setPredicate(PredicateType.IS_NOT_IN)
213+
214+
when:
205215
user.with("userId", "3")
206216
def hitSuccess = condition.matchObjects(user, segments)
207217
user.with("userId", "1")
@@ -218,13 +228,13 @@ class ConditionSpec extends Specification {
218228
condition.setObjects([Instant.now().getEpochSecond().toString()])
219229
condition.setPredicate(PredicateType.AFTER)
220230
user.with("userId", (Instant.now().getEpochSecond()).toString())
221-
def hitSuccess1 = condition.matchObjects(user, segments)
231+
def hitSuccess1 = condition.matchObjects(user, [:])
222232
user.with("userId", (Instant.now().getEpochSecond() + 1).toString())
223-
def hitSuccess2 = condition.matchObjects(user, segments)
233+
def hitSuccess2 = condition.matchObjects(user, [:])
224234
user.with("userId", null)
225-
def hitSuccess3 = condition.matchObjects(user, segments)
235+
def hitSuccess3 = condition.matchObjects(user, [:])
226236
user.with("userId", "1000")
227-
def hitMiss = condition.matchObjects(user, segments)
237+
def hitMiss = condition.matchObjects(user, [:])
228238

229239
then:
230240
hitSuccess1
@@ -239,11 +249,11 @@ class ConditionSpec extends Specification {
239249
condition.setObjects([Instant.now().getEpochSecond().toString()])
240250
condition.setPredicate(PredicateType.BEFORE)
241251
user.with("userId", (Instant.now().getEpochSecond() - 2).toString())
242-
def hitSuccess = condition.matchObjects(user, segments)
252+
def hitSuccess = condition.matchObjects(user, [:])
243253
user.with("userId", (Instant.now().getEpochSecond() + 1).toString())
244-
def hitMiss1 = condition.matchObjects(user, segments)
254+
def hitMiss1 = condition.matchObjects(user, [:])
245255
user.with("userId", "invalid date")
246-
def hitMiss2 = condition.matchObjects(user, segments)
256+
def hitMiss2 = condition.matchObjects(user, [:])
247257

248258
then:
249259
hitSuccess
@@ -257,13 +267,13 @@ class ConditionSpec extends Specification {
257267
condition.setObjects(["12", "10.1"])
258268
condition.setPredicate(PredicateType.EQUAL_TO)
259269
user.with("userId", " 12.000000 \n")
260-
def hitSuccess1 = condition.matchObjects(user, segments)
270+
def hitSuccess1 = condition.matchObjects(user, [:])
261271
user.with("userId", " 10.10 \n")
262-
def hitSuccess2 = condition.matchObjects(user, segments)
272+
def hitSuccess2 = condition.matchObjects(user, [:])
263273
user.with("userId", "foo.bar+1")
264-
def hitMiss1 = condition.matchObjects(user, segments)
274+
def hitMiss1 = condition.matchObjects(user, [:])
265275
user.with("userId", " ")
266-
def hitMiss2 = condition.matchObjects(user, segments)
276+
def hitMiss2 = condition.matchObjects(user, [:])
267277

268278
then:
269279
hitSuccess1
@@ -278,15 +288,15 @@ class ConditionSpec extends Specification {
278288
condition.setObjects(["12", "16"])
279289
condition.setPredicate(PredicateType.NOT_EQUAL_TO)
280290
user.with("userId", " 13 \n")
281-
def hitSuccess = condition.matchObjects(user, segments)
291+
def hitSuccess = condition.matchObjects(user, [:])
282292
user.with("userId", "\t16.0 ")
283-
def hitMiss1 = condition.matchObjects(user, segments)
293+
def hitMiss1 = condition.matchObjects(user, [:])
284294
user.with("userId", "foo")
285-
def hitMiss2 = condition.matchObjects(user, segments)
295+
def hitMiss2 = condition.matchObjects(user, [:])
286296

287297
condition.setObjects(["foo", "16"])
288298
user.with("userId", "1")
289-
def hitMiss3 = condition.matchObjects(user, segments)
299+
def hitMiss3 = condition.matchObjects(user, [:])
290300

291301
then:
292302
hitSuccess
@@ -301,11 +311,11 @@ class ConditionSpec extends Specification {
301311
condition.setObjects(["12"])
302312
condition.setPredicate(PredicateType.GREATER_THAN)
303313
user.with("userId", " 13 \n")
304-
def hitSuccess = condition.matchObjects(user, segments)
314+
def hitSuccess = condition.matchObjects(user, [:])
305315
user.with("userId", "\t11.998 ")
306-
def hitMiss1 = condition.matchObjects(user, segments)
316+
def hitMiss1 = condition.matchObjects(user, [:])
307317
user.with("userId", "\t12.0 ")
308-
def hitMiss2 = condition.matchObjects(user, segments)
318+
def hitMiss2 = condition.matchObjects(user, [:])
309319

310320
then:
311321
hitSuccess
@@ -319,11 +329,11 @@ class ConditionSpec extends Specification {
319329
condition.setObjects(["12"])
320330
condition.setPredicate(PredicateType.GREATER_OR_EQUAL)
321331
user.with("userId", " 13 \n")
322-
def hitSuccess1 = condition.matchObjects(user, segments)
332+
def hitSuccess1 = condition.matchObjects(user, [:])
323333
user.with("userId", "\t12.0 ")
324-
def hitSuccess2 = condition.matchObjects(user, segments)
334+
def hitSuccess2 = condition.matchObjects(user, [:])
325335
user.with("userId", "\t11.919999998 ")
326-
def hitMiss = condition.matchObjects(user, segments)
336+
def hitMiss = condition.matchObjects(user, [:])
327337

328338
then:
329339
hitSuccess1
@@ -337,11 +347,11 @@ class ConditionSpec extends Specification {
337347
condition.setObjects(["17"])
338348
condition.setPredicate(PredicateType.LESS_THAN)
339349
user.with("userId", " 13 \n")
340-
def hitSuccess = condition.matchObjects(user, segments)
350+
def hitSuccess = condition.matchObjects(user, [:])
341351
user.with("userId", "\t18")
342-
def hitMiss1 = condition.matchObjects(user, segments)
352+
def hitMiss1 = condition.matchObjects(user, [:])
343353
user.with("userId", "\t17.00000000000001 ") // parsed as 17
344-
def hitMiss2 = condition.matchObjects(user, segments)
354+
def hitMiss2 = condition.matchObjects(user, [:])
345355

346356
then:
347357
hitSuccess
@@ -355,11 +365,11 @@ class ConditionSpec extends Specification {
355365
condition.setObjects(["17"])
356366
condition.setPredicate(PredicateType.LESS_OR_EQUAL)
357367
user.with("userId", " 13 \n")
358-
def hitSuccess1 = condition.matchObjects(user, segments)
368+
def hitSuccess1 = condition.matchObjects(user, [:])
359369
user.with("userId", "17")
360-
def hitSuccess2 = condition.matchObjects(user, segments)
370+
def hitSuccess2 = condition.matchObjects(user, [:])
361371
user.with("userId", "\t18")
362-
def hitMiss = condition.matchObjects(user, segments)
372+
def hitMiss = condition.matchObjects(user, [:])
363373

364374
then:
365375
hitSuccess1
@@ -373,13 +383,13 @@ class ConditionSpec extends Specification {
373383
condition.setObjects(["1.1.3", "1.1.5"])
374384
condition.setPredicate(PredicateType.EQUAL_TO)
375385
user.with("userId", "1.1.3")
376-
def hitSuccess1 = condition.matchObjects(user, segments)
386+
def hitSuccess1 = condition.matchObjects(user, [:])
377387
user.with("userId", "1.1.5")
378-
def hitSuccess2 = condition.matchObjects(user, segments)
388+
def hitSuccess2 = condition.matchObjects(user, [:])
379389
user.with("userId", "1.0.1")
380-
def hitMiss1 = condition.matchObjects(user, segments)
390+
def hitMiss1 = condition.matchObjects(user, [:])
381391
user.with("userId", "")
382-
def hitMiss2 = condition.matchObjects(user, segments)
392+
def hitMiss2 = condition.matchObjects(user, [:])
383393

384394
then:
385395
hitSuccess1
@@ -394,11 +404,11 @@ class ConditionSpec extends Specification {
394404
condition.setObjects(["1.1.0", "1.2.0"])
395405
condition.setPredicate(PredicateType.NOT_EQUAL_TO)
396406
user.with("userId", "1.3.0")
397-
def hitSuccess = condition.matchObjects(user, segments)
407+
def hitSuccess = condition.matchObjects(user, [:])
398408
user.with("userId", "1.1.0")
399-
def hitMiss1 = condition.matchObjects(user, segments)
409+
def hitMiss1 = condition.matchObjects(user, [:])
400410
user.with("userId", "1.2.0")
401-
def hitMiss2 = condition.matchObjects(user, segments)
411+
def hitMiss2 = condition.matchObjects(user, [:])
402412

403413
then:
404414
hitSuccess
@@ -412,9 +422,9 @@ class ConditionSpec extends Specification {
412422
condition.setObjects(["1.1.0", "1.2.0"])
413423
condition.setPredicate(PredicateType.GREATER_THAN)
414424
user.with("userId", "1.1.1")
415-
def hitSuccess = condition.matchObjects(user, segments)
425+
def hitSuccess = condition.matchObjects(user, [:])
416426
user.with("userId", "1.0.0")
417-
def hitMiss = condition.matchObjects(user, segments)
427+
def hitMiss = condition.matchObjects(user, [:])
418428

419429
then:
420430
hitSuccess
@@ -427,11 +437,11 @@ class ConditionSpec extends Specification {
427437
condition.setObjects(["1.1.0", "1.2.0"])
428438
condition.setPredicate(PredicateType.GREATER_OR_EQUAL)
429439
user.with("userId", "1.1.1")
430-
def hitSuccess1 = condition.matchObjects(user, segments)
440+
def hitSuccess1 = condition.matchObjects(user, [:])
431441
user.with("userId", "1.1.0")
432-
def hitSuccess2 = condition.matchObjects(user, segments)
442+
def hitSuccess2 = condition.matchObjects(user, [:])
433443
user.with("userId", "1.0.0")
434-
def hitMiss = condition.matchObjects(user, segments)
444+
def hitMiss = condition.matchObjects(user, [:])
435445

436446
then:
437447
hitSuccess1
@@ -445,11 +455,11 @@ class ConditionSpec extends Specification {
445455
condition.setObjects(["1.1.0", "1.2.0"])
446456
condition.setPredicate(PredicateType.LESS_THAN)
447457
user.with("userId", "1.0.1")
448-
def hitSuccess1 = condition.matchObjects(user, segments)
458+
def hitSuccess1 = condition.matchObjects(user, [:])
449459
user.with("userId", "1.1.7")
450-
def hitSuccess2 = condition.matchObjects(user, segments)
460+
def hitSuccess2 = condition.matchObjects(user, [:])
451461
user.with("userId", "1.2.0")
452-
def hitMiss = condition.matchObjects(user, segments)
462+
def hitMiss = condition.matchObjects(user, [:])
453463

454464
then:
455465
hitSuccess1
@@ -463,11 +473,11 @@ class ConditionSpec extends Specification {
463473
condition.setObjects(["1.1.0", "1.2.0"])
464474
condition.setPredicate(PredicateType.LESS_OR_EQUAL)
465475
user.with("userId", "1.0.1")
466-
def hitSuccess1 = condition.matchObjects(user, segments)
476+
def hitSuccess1 = condition.matchObjects(user, [:])
467477
user.with("userId", "1.2.0")
468-
def hitSuccess2 = condition.matchObjects(user, segments)
478+
def hitSuccess2 = condition.matchObjects(user, [:])
469479
user.with("userId", "1.2.1")
470-
def hitMiss = condition.matchObjects(user, segments)
480+
def hitMiss = condition.matchObjects(user, [:])
471481

472482
then:
473483
hitSuccess1

0 commit comments

Comments
 (0)