Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: pkg/shelf/test/message_test.dart

Issue 239183005: Add a context field to Message in shelf. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/shelf/pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/shelf/test/message_test.dart
diff --git a/pkg/shelf/test/message_test.dart b/pkg/shelf/test/message_test.dart
index 57f32c4afe0258ed661063219b4e06ed04cac819..1db286ba4495ca691c3b5978e38138352cca577b 100644
--- a/pkg/shelf/test/message_test.dart
+++ b/pkg/shelf/test/message_test.dart
@@ -11,13 +11,15 @@ import 'package:shelf/src/message.dart';
import 'package:unittest/unittest.dart';
class _TestMessage extends Message {
- _TestMessage(Map<String, String> headers, Stream<List<int>> body)
- : super(body, headers: headers);
+ _TestMessage(Map<String, String> headers, Map<String, Object> context,
+ Stream<List<int>> body)
+ : super(body, headers: headers, context: context);
}
-Message _createMessage({Map<String, String> headers, Stream<List<int>> body}) {
+Message _createMessage({Map<String, String> headers,
+ Map<String, Object> context, Stream<List<int>> body}) {
if (body == null) body = new Stream.fromIterable([]);
- return new _TestMessage(headers, body);
+ return new _TestMessage(headers, context, body);
}
void main() {
@@ -43,6 +45,26 @@ void main() {
expect(() => message.headers['h2'] = 'value2', throwsUnsupportedError);
});
});
+
+ group('context', () {
+ test('is accessible', () {
+ var message = _createMessage(context: {'foo': 'bar'});
+ expect(message.context, containsPair('foo', 'bar'));
+ });
+
+ test('null context value becomes empty and immutable', () {
+ var message = _createMessage();
+ expect(message.context, isEmpty);
+ expect(() => message.context['key'] = 'value', throwsUnsupportedError);
+ });
+
+ test('is immutable', () {
+ var message = _createMessage(context: {'key': 'value'});
+ expect(() => message.context['key'] = 'value', throwsUnsupportedError);
+ expect(() => message.context['key2'] = 'value', throwsUnsupportedError);
+ });
+ });
+
group("readAsString", () {
test("supports a null body", () {
var request = _createMessage();
« no previous file with comments | « pkg/shelf/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698