1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func TestParseIfHeader(t *testing.T) {
14 // The "section x.y.z" test cases come from section x.y.z of the spec at
15 // http://www.webdav.org/specs/rfc4918.html
16 testCases := []struct {
37 "bad: no list after resource #1",
41 "bad: no list after resource #2",
45 "bad: no list after resource #3",
46 `<foo> (a) (b) <bar>`,
49 "bad: no-tag-list followed by tagged-list",
53 "bad: unfinished list",
57 "bad: unfinished ETag",
61 "bad: unfinished Notted list",
69 "good: one list with a Token",
73 conditions: []Condition{{
79 "good: one list with an ETag",
83 conditions: []Condition{{
89 "good: one list with three Nots",
90 `(Not a Not b Not [d])`,
93 conditions: []Condition{{
110 conditions: []Condition{{
114 conditions: []Condition{{
120 "good: two Notted lists",
124 conditions: []Condition{{
129 conditions: []Condition{{
137 `<http://www.example.com/users/f/fielding/index.html>
138 (<urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6>)`,
141 resourceTag: `http://www.example.com/users/f/fielding/index.html`,
142 conditions: []Condition{{
143 Token: `urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6`,
149 `(<urn:uuid:150852e2-3847-42d5-8cbe-0f4f296f26cf>)`,
152 conditions: []Condition{{
153 Token: `urn:uuid:150852e2-3847-42d5-8cbe-0f4f296f26cf`,
159 `<http://example.com/locked/>
160 (<urn:uuid:150852e2-3847-42d5-8cbe-0f4f296f26cf>)`,
163 resourceTag: `http://example.com/locked/`,
164 conditions: []Condition{{
165 Token: `urn:uuid:150852e2-3847-42d5-8cbe-0f4f296f26cf`,
171 `<http://example.com/locked/member>
172 (<urn:uuid:150852e2-3847-42d5-8cbe-0f4f296f26cf>)`,
175 resourceTag: `http://example.com/locked/member`,
176 conditions: []Condition{{
177 Token: `urn:uuid:150852e2-3847-42d5-8cbe-0f4f296f26cf`,
183 `(<urn:uuid:fe184f2e-6eec-41d0-c765-01adc56e6bb4>)
184 (<urn:uuid:e454f3f3-acdc-452a-56c7-00a5c91e4b77>)`,
187 conditions: []Condition{{
188 Token: `urn:uuid:fe184f2e-6eec-41d0-c765-01adc56e6bb4`,
191 conditions: []Condition{{
192 Token: `urn:uuid:e454f3f3-acdc-452a-56c7-00a5c91e4b77`,
198 `(<urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>)`,
201 conditions: []Condition{{
202 Token: `urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4`,
208 `(<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>
210 (["I am another ETag"])`,
213 conditions: []Condition{{
214 Token: `urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2`,
216 ETag: `"I am an ETag"`,
219 conditions: []Condition{{
220 ETag: `"I am another ETag"`,
226 `(Not <urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>
227 <urn:uuid:58f202ac-22cf-11d1-b12d-002035b29092>)`,
230 conditions: []Condition{{
232 Token: `urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2`,
234 Token: `urn:uuid:58f202ac-22cf-11d1-b12d-002035b29092`,
240 `(<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>)
241 (Not <DAV:no-lock>)`,
244 conditions: []Condition{{
245 Token: `urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2`,
248 conditions: []Condition{{
250 Token: `DAV:no-lock`,
257 (<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>
258 [W/"A weak ETag"]) (["strong ETag"])`,
261 resourceTag: `/resource1`,
262 conditions: []Condition{{
263 Token: `urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2`,
265 ETag: `W/"A weak ETag"`,
268 resourceTag: `/resource1`,
269 conditions: []Condition{{
270 ETag: `"strong ETag"`,
276 `<http://www.example.com/specs/>
277 (<urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2>)`,
280 resourceTag: `http://www.example.com/specs/`,
281 conditions: []Condition{{
282 Token: `urn:uuid:181d4fae-7d8c-11d0-a765-00a0c91e6bf2`,
287 "section 10.4.11 #1",
288 `</specs/rfc2518.doc> (["4217"])`,
291 resourceTag: `/specs/rfc2518.doc`,
292 conditions: []Condition{{
298 "section 10.4.11 #2",
299 `</specs/rfc2518.doc> (Not ["4217"])`,
302 resourceTag: `/specs/rfc2518.doc`,
303 conditions: []Condition{{
311 for _, tc := range testCases {
312 got, ok := parseIfHeader(strings.Replace(tc.input, "\n", "", -1))
313 if gotEmpty := reflect.DeepEqual(got, ifHeader{}); gotEmpty == ok {
314 t.Errorf("%s: should be different: empty header == %t, ok == %t", tc.desc, gotEmpty, ok)
317 if !reflect.DeepEqual(got, tc.want) {
318 t.Errorf("%s:\ngot %v\nwant %v", tc.desc, got, tc.want)