@@ -206,6 +206,16 @@ func TestURLsCost(t *testing.T) {
206
206
expectEsimatedCost : checker.CostEstimate {Min : 4 , Max : 4 },
207
207
expectRuntimeCost : 4 ,
208
208
},
209
+ {
210
+ ops : []string {" == url('https:://kubernetes.io/')" },
211
+ expectEsimatedCost : checker.CostEstimate {Min : 7 , Max : 9 },
212
+ expectRuntimeCost : 7 ,
213
+ },
214
+ {
215
+ ops : []string {" == url('http://x.b')" },
216
+ expectEsimatedCost : checker.CostEstimate {Min : 5 , Max : 5 },
217
+ expectRuntimeCost : 5 ,
218
+ },
209
219
}
210
220
211
221
for _ , tc := range cases {
@@ -245,6 +255,14 @@ func TestIPCost(t *testing.T) {
245
255
},
246
256
expectRuntimeCost : func (c uint64 ) uint64 { return c + 1 },
247
257
},
258
+ {
259
+ ops : []string {" == ip('192.168.0.1')" },
260
+ // For most other operations, the cost is expected to be the base + 1.
261
+ expectEsimatedCost : func (c checker.CostEstimate ) checker.CostEstimate {
262
+ return c .Add (ipv4BaseEstimatedCost ).Add (checker.CostEstimate {Min : 1 , Max : 1 })
263
+ },
264
+ expectRuntimeCost : func (c uint64 ) uint64 { return c + ipv4BaseRuntimeCost + 1 },
265
+ },
248
266
}
249
267
250
268
for _ , tc := range testCases {
@@ -320,6 +338,14 @@ func TestCIDRCost(t *testing.T) {
320
338
},
321
339
expectRuntimeCost : func (c uint64 ) uint64 { return c + 1 },
322
340
},
341
+ {
342
+ ops : []string {" == cidr('2001:db8::/32')" },
343
+ // For most other operations, the cost is expected to be the base + 1.
344
+ expectEsimatedCost : func (c checker.CostEstimate ) checker.CostEstimate {
345
+ return c .Add (ipv6BaseEstimatedCost ).Add (checker.CostEstimate {Min : 1 , Max : 1 })
346
+ },
347
+ expectRuntimeCost : func (c uint64 ) uint64 { return c + ipv6BaseRuntimeCost + 1 },
348
+ },
323
349
}
324
350
325
351
//nolint:gocritic
@@ -708,19 +734,19 @@ func TestQuantityCost(t *testing.T) {
708
734
{
709
735
name : "equality_reflexivity" ,
710
736
expr : `quantity("200M") == quantity("200M")` ,
711
- expectEstimatedCost : checker.CostEstimate {Min : 3 , Max : 1844674407370955266 },
737
+ expectEstimatedCost : checker.CostEstimate {Min : 3 , Max : 3 },
712
738
expectRuntimeCost : 3 ,
713
739
},
714
740
{
715
741
name : "equality_symmetry" ,
716
742
expr : `quantity("200M") == quantity("0.2G") && quantity("0.2G") == quantity("200M")` ,
717
- expectEstimatedCost : checker.CostEstimate {Min : 3 , Max : 3689348814741910532 },
743
+ expectEstimatedCost : checker.CostEstimate {Min : 3 , Max : 6 },
718
744
expectRuntimeCost : 6 ,
719
745
},
720
746
{
721
747
name : "equality_transitivity" ,
722
748
expr : `quantity("2M") == quantity("0.002G") && quantity("2000k") == quantity("2M") && quantity("0.002G") == quantity("2000k")` ,
723
- expectEstimatedCost : checker.CostEstimate {Min : 3 , Max : 5534023222112865798 },
749
+ expectEstimatedCost : checker.CostEstimate {Min : 3 , Max : 9 },
724
750
expectRuntimeCost : 9 ,
725
751
},
726
752
{
@@ -744,19 +770,19 @@ func TestQuantityCost(t *testing.T) {
744
770
{
745
771
name : "add_quantity" ,
746
772
expr : `quantity("50k").add(quantity("20")) == quantity("50.02k")` ,
747
- expectEstimatedCost : checker.CostEstimate {Min : 5 , Max : 1844674407370955268 },
773
+ expectEstimatedCost : checker.CostEstimate {Min : 5 , Max : 5 },
748
774
expectRuntimeCost : 5 ,
749
775
},
750
776
{
751
777
name : "sub_quantity" ,
752
778
expr : `quantity("50k").sub(quantity("20")) == quantity("49.98k")` ,
753
- expectEstimatedCost : checker.CostEstimate {Min : 5 , Max : 1844674407370955268 },
779
+ expectEstimatedCost : checker.CostEstimate {Min : 5 , Max : 5 },
754
780
expectRuntimeCost : 5 ,
755
781
},
756
782
{
757
783
name : "sub_int" ,
758
784
expr : `quantity("50k").sub(20) == quantity("49980")` ,
759
- expectEstimatedCost : checker.CostEstimate {Min : 4 , Max : 1844674407370955267 },
785
+ expectEstimatedCost : checker.CostEstimate {Min : 4 , Max : 4 },
760
786
expectRuntimeCost : 4 ,
761
787
},
762
788
{
@@ -825,6 +851,18 @@ func TestNameFormatCost(t *testing.T) {
825
851
expectEstimatedCost : checker.CostEstimate {Min : 34 , Max : 34 },
826
852
expectRuntimeCost : 10 ,
827
853
},
854
+ {
855
+ name : "format.dns1123label.validate" ,
856
+ expr : `format.named("dns1123Label").value().validate("my-name")` ,
857
+ expectEstimatedCost : checker.CostEstimate {Min : 34 , Max : 34 },
858
+ expectRuntimeCost : 10 ,
859
+ },
860
+ {
861
+ name : "format.dns1123label.validate" ,
862
+ expr : `format.named("dns1123Label").value() == format.named("dns1123Label").value()` ,
863
+ expectEstimatedCost : checker.CostEstimate {Min : 5 , Max : 11 },
864
+ expectRuntimeCost : 5 ,
865
+ },
828
866
}
829
867
830
868
for _ , tc := range cases {
0 commit comments