1
- import { R2Conditional } from "@cloudflare/workers-types/experimental" ;
2
- import { R2Object , _testR2Conditional } from "@miniflare/tre" ;
1
+ import { R2Conditional , R2Object , _testR2Conditional } from "@miniflare/tre" ;
3
2
import test from "ava" ;
4
3
5
4
test ( "testR2Conditional: matches various conditions" , ( t ) => {
@@ -20,89 +19,146 @@ test("testR2Conditional: matches various conditions", (t) => {
20
19
const usingMissing = ( cond : R2Conditional ) => _testR2Conditional ( cond ) ;
21
20
22
21
// Check single conditions
23
- t . true ( using( { etagMatches : etag } ) ) ;
24
- t . false ( using( { etagMatches : badEtag } ) ) ;
22
+ t . true ( using( { etagMatches : [ { type : "strong" , value : etag } ] } ) ) ;
23
+ t . false ( using( { etagMatches : [ { type : "strong" , value : badEtag } ] } ) ) ;
25
24
26
- t . true ( using( { etagDoesNotMatch : badEtag } ) ) ;
27
- t . false ( using( { etagDoesNotMatch : etag } ) ) ;
25
+ t . true ( using( { etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] } ) ) ;
26
+ t . false ( using( { etagDoesNotMatch : [ { type : "strong" , value : etag } ] } ) ) ;
28
27
29
28
t . false ( using( { uploadedBefore : pastDate } ) ) ;
30
29
t . true ( using( { uploadedBefore : futureDate } ) ) ;
31
30
32
31
t . true ( using( { uploadedAfter : pastDate } ) ) ;
33
32
t . false ( using( { uploadedBefore : pastDate } ) ) ;
34
33
34
+ // Check with weaker etags
35
+ t . false ( using( { etagMatches : [ { type : "weak" , value : etag } ] } ) ) ;
36
+ t . false ( using( { etagDoesNotMatch : [ { type : "weak" , value : etag } ] } ) ) ;
37
+ t . true ( using( { etagDoesNotMatch : [ { type : "weak" , value : badEtag } ] } ) ) ;
38
+ t . true ( using( { etagMatches : [ { type : "wildcard" } ] } ) ) ;
39
+ t . false ( using( { etagDoesNotMatch : [ { type : "wildcard" } ] } ) ) ;
40
+
35
41
// Check multiple conditions that evaluate to false
36
- t . false ( using( { etagMatches : etag , etagDoesNotMatch : etag } ) ) ;
37
- t . false ( using( { etagMatches : etag , uploadedAfter : futureDate } ) ) ;
42
+ t . false (
43
+ using( {
44
+ etagMatches : [ { type : "strong" , value : etag } ] ,
45
+ etagDoesNotMatch : [ { type : "strong" , value : etag } ] ,
46
+ } )
47
+ ) ;
48
+ t . false (
49
+ using( {
50
+ etagMatches : [ { type : "strong" , value : etag } ] ,
51
+ uploadedAfter : futureDate ,
52
+ } )
53
+ ) ;
38
54
t . false (
39
55
using( {
40
56
// `etagMatches` pass makes `uploadedBefore` pass, but `uploadedAfter` fails
41
- etagMatches : etag ,
57
+ etagMatches : [ { type : "strong" , value : etag } ] ,
42
58
uploadedAfter : futureDate ,
43
59
uploadedBefore : pastDate ,
44
60
} )
45
61
) ;
46
- t . false ( using( { etagDoesNotMatch : badEtag , uploadedBefore : pastDate } ) ) ;
62
+ t . false (
63
+ using( {
64
+ etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] ,
65
+ uploadedBefore : pastDate ,
66
+ } )
67
+ ) ;
47
68
t . false (
48
69
using( {
49
70
// `etagDoesNotMatch` pass makes `uploadedAfter` pass, but `uploadedBefore` fails
50
- etagDoesNotMatch : badEtag ,
71
+ etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] ,
51
72
uploadedAfter : futureDate ,
52
73
uploadedBefore : pastDate ,
53
74
} )
54
75
) ;
55
76
t . false (
56
77
using( {
57
- etagMatches : badEtag ,
58
- etagDoesNotMatch : badEtag ,
78
+ etagMatches : [ { type : "strong" , value : badEtag } ] ,
79
+ etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] ,
59
80
uploadedAfter : pastDate ,
60
81
uploadedBefore : futureDate ,
61
82
} )
62
83
) ;
63
84
64
85
// Check multiple conditions that evaluate to true
65
- t . true ( using( { etagMatches : etag , etagDoesNotMatch : badEtag } ) ) ;
86
+ t . true (
87
+ using( {
88
+ etagMatches : [ { type : "strong" , value : etag } ] ,
89
+ etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] ,
90
+ } )
91
+ ) ;
66
92
// `etagMatches` pass makes `uploadedBefore` pass
67
- t . true ( using( { etagMatches : etag , uploadedBefore : pastDate } ) ) ;
93
+ t . true (
94
+ using( {
95
+ etagMatches : [ { type : "strong" , value : etag } ] ,
96
+ uploadedBefore : pastDate ,
97
+ } )
98
+ ) ;
68
99
// `etagDoesNotMatch` pass makes `uploadedAfter` pass
69
- t . true ( using( { etagDoesNotMatch : badEtag , uploadedAfter : futureDate } ) ) ;
100
+ t . true (
101
+ using( {
102
+ etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] ,
103
+ uploadedAfter : futureDate ,
104
+ } )
105
+ ) ;
70
106
t . true (
71
107
using( {
72
108
// `etagMatches` pass makes `uploadedBefore` pass
73
- etagMatches : etag ,
109
+ etagMatches : [ { type : "strong" , value : etag } ] ,
74
110
uploadedBefore : pastDate ,
75
111
// `etagDoesNotMatch` pass makes `uploadedAfter` pass
76
- etagDoesNotMatch : badEtag ,
112
+ etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] ,
77
113
uploadedAfter : futureDate ,
78
114
} )
79
115
) ;
80
116
t . true (
81
117
using( {
82
118
uploadedBefore : futureDate ,
83
119
// `etagDoesNotMatch` pass makes `uploadedAfter` pass
84
- etagDoesNotMatch : badEtag ,
120
+ etagDoesNotMatch : [ { type : "strong" , value : badEtag } ] ,
85
121
uploadedAfter : futureDate ,
86
122
} )
87
123
) ;
88
124
t . true (
89
125
using( {
90
126
uploadedAfter : pastDate ,
91
127
// `etagMatches` pass makes `uploadedBefore` pass
92
- etagMatches : etag ,
128
+ etagMatches : [ { type : "strong" , value : etag } ] ,
93
129
uploadedBefore : pastDate ,
94
130
} )
95
131
) ;
96
132
97
133
// Check missing metadata fails with either `etagMatches` and `uploadedAfter`
98
- t . false ( usingMissing ( { etagMatches : etag } ) ) ;
134
+ t . false ( usingMissing ( { etagMatches : [ { type : "strong" , value : etag } ] } ) ) ;
99
135
t . false ( usingMissing ( { uploadedAfter : pastDate } ) ) ;
100
- t . false ( usingMissing ( { etagMatches : etag , uploadedAfter : pastDate } ) ) ;
101
- t . true ( usingMissing ( { etagDoesNotMatch : etag } ) ) ;
136
+ t . false (
137
+ usingMissing ( {
138
+ etagMatches : [ { type : "strong" , value : etag } ] ,
139
+ uploadedAfter : pastDate ,
140
+ } )
141
+ ) ;
142
+ t . true ( usingMissing ( { etagDoesNotMatch : [ { type : "strong" , value : etag } ] } ) ) ;
102
143
t . true ( usingMissing ( { uploadedBefore : pastDate } ) ) ;
103
- t . true ( usingMissing ( { etagDoesNotMatch : etag , uploadedBefore : pastDate } ) ) ;
104
- t . false ( usingMissing ( { etagMatches : etag , uploadedBefore : pastDate } ) ) ;
105
- t . false ( usingMissing ( { etagDoesNotMatch : etag , uploadedAfter : pastDate } ) ) ;
144
+ t . true (
145
+ usingMissing ( {
146
+ etagDoesNotMatch : [ { type : "strong" , value : etag } ] ,
147
+ uploadedBefore : pastDate ,
148
+ } )
149
+ ) ;
150
+ t . false (
151
+ usingMissing ( {
152
+ etagMatches : [ { type : "strong" , value : etag } ] ,
153
+ uploadedBefore : pastDate ,
154
+ } )
155
+ ) ;
156
+ t . false (
157
+ usingMissing ( {
158
+ etagDoesNotMatch : [ { type : "strong" , value : etag } ] ,
159
+ uploadedAfter : pastDate ,
160
+ } )
161
+ ) ;
106
162
107
163
// Check with second granularity
108
164
const justPastDate = new Date ( uploadedDate . getTime ( ) - 250 ) ;
0 commit comments