| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library multipart_test; | 5 library multipart_test; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:utf'; | 8 import 'dart:utf'; |
| 9 | 9 |
| 10 // TODO(nweiz): get rid of this import before packaging this | 10 // TODO(nweiz): get rid of this import before packaging this |
| 11 import '../../../tests/utils/test_utils.dart'; | 11 import '../../../tests/utils/test_utils.dart'; |
| 12 // TODO(nweiz): make these package: imports | 12 import 'package:unittest/unittest.dart'; |
| 13 import '../../unittest/lib/unittest.dart'; | 13 import 'package:http/http.dart' as http; |
| 14 import '../lib/http.dart' as http; | 14 import 'package:http/src/utils.dart'; |
| 15 import '../lib/src/utils.dart'; | |
| 16 | 15 |
| 17 import 'utils.dart'; | 16 import 'utils.dart'; |
| 18 | 17 |
| 19 /// A matcher that validates the body of a multipart request after finalization. | 18 /// A matcher that validates the body of a multipart request after finalization. |
| 20 /// The string "{{boundary}}" in [pattern] will be replaced by the boundary | 19 /// The string "{{boundary}}" in [pattern] will be replaced by the boundary |
| 21 /// string for the request, and LF newlines will be replaced with CRLF. | 20 /// string for the request, and LF newlines will be replaced with CRLF. |
| 22 /// Indentation will be normalized. | 21 /// Indentation will be normalized. |
| 23 Matcher bodyMatches(String pattern) => new _BodyMatches(pattern); | 22 Matcher bodyMatches(String pattern) => new _BodyMatches(pattern); |
| 24 | 23 |
| 25 class _BodyMatches extends BaseMatcher { | 24 class _BodyMatches extends BaseMatcher { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 var request = new http.MultipartRequest('POST', dummyUrl); | 175 var request = new http.MultipartRequest('POST', dummyUrl); |
| 177 var stream = new ListInputStream(); | 176 var stream = new ListInputStream(); |
| 178 stream.markEndOfStream(); | 177 stream.markEndOfStream(); |
| 179 request.files.add(new http.MultipartFile('file', stream, 0)); | 178 request.files.add(new http.MultipartFile('file', stream, 0)); |
| 180 | 179 |
| 181 expect(request, bodyMatches(''' | 180 expect(request, bodyMatches(''' |
| 182 --{{boundary}} | 181 --{{boundary}} |
| 183 content-type: application/octet-stream | 182 content-type: application/octet-stream |
| 184 content-disposition: form-data; name="file" | 183 content-disposition: form-data; name="file" |
| 185 | 184 |
| 186 | 185 |
| 187 --{{boundary}}-- | 186 --{{boundary}}-- |
| 188 ''')); | 187 ''')); |
| 189 }); | 188 }); |
| 190 | 189 |
| 191 test('with a byte file', () { | 190 test('with a byte file', () { |
| 192 var request = new http.MultipartRequest('POST', dummyUrl); | 191 var request = new http.MultipartRequest('POST', dummyUrl); |
| 193 var file = new http.MultipartFile.fromBytes( | 192 var file = new http.MultipartFile.fromBytes( |
| 194 'file', [104, 101, 108, 108, 111]); | 193 'file', [104, 101, 108, 108, 111]); |
| 195 request.files.add(file); | 194 request.files.add(file); |
| 196 | 195 |
| 197 expect(request, bodyMatches(''' | 196 expect(request, bodyMatches(''' |
| 198 --{{boundary}} | 197 --{{boundary}} |
| 199 content-type: application/octet-stream | 198 content-type: application/octet-stream |
| 200 content-disposition: form-data; name="file" | 199 content-disposition: form-data; name="file" |
| 201 | 200 |
| 202 hello | 201 hello |
| 203 --{{boundary}}-- | 202 --{{boundary}}-- |
| 204 ''')); | 203 ''')); |
| 205 }); | 204 }); |
| 206 } | 205 } |
| OLD | NEW |