-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for Message #90
Merged
+448
−3
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
|
||
import 'package:test/test.dart'; | ||
|
||
import 'package:http/http.dart'; | ||
import 'package:http/src/message.dart'; | ||
|
||
final _uri = Uri.parse('http://localhost/'); | ||
|
||
void main() { | ||
group('Request', () { | ||
_testChange(({body, headers, context}) { | ||
return new Request('GET', _uri, | ||
body: body, headers: headers, context: context); | ||
}); | ||
}); | ||
|
||
group('Response', () { | ||
_testChange(({body, headers, context}) { | ||
return new Response(_uri, 200, | ||
body: body, headers: headers, context: context); | ||
}); | ||
}); | ||
} | ||
|
||
/// Shared test method used by [Request] and [Response] tests to validate | ||
/// the behavior of `change` with different `headers` and `context` values. | ||
void _testChange( | ||
Message factory( | ||
{body, Map<String, String> headers, Map<String, Object> context})) { | ||
group('body', () { | ||
test('with String', () async { | ||
var request = factory(body: 'Hello, world'); | ||
var copy = request.change(body: 'Goodbye, world'); | ||
|
||
var newBody = await copy.readAsString(); | ||
|
||
expect(newBody, equals('Goodbye, world')); | ||
}); | ||
|
||
test('with Stream', () async { | ||
var request = factory(body: 'Hello, world'); | ||
var copy = request.change( | ||
body: new Stream.fromIterable(['Goodbye, world']) | ||
.transform(UTF8.encoder)); | ||
|
||
var newBody = await copy.readAsString(); | ||
|
||
expect(newBody, equals('Goodbye, world')); | ||
}); | ||
}); | ||
|
||
test('with empty headers returns identical instance', () { | ||
var request = factory(headers: {'header1': 'header value 1'}); | ||
var copy = request.change(headers: {}); | ||
|
||
expect(copy.headers, same(request.headers)); | ||
}); | ||
|
||
test('with empty context returns identical instance', () { | ||
var request = factory(context: {'context1': 'context value 1'}); | ||
var copy = request.change(context: {}); | ||
|
||
expect(copy.context, same(request.context)); | ||
}); | ||
|
||
test('new header values are added', () { | ||
var request = factory(headers: {'test': 'test value'}); | ||
var copy = request.change(headers: {'test2': 'test2 value'}); | ||
|
||
expect(copy.headers, | ||
{'test': 'test value', 'test2': 'test2 value', 'content-length': '0'}); | ||
}); | ||
|
||
test('existing header values are overwritten', () { | ||
var request = factory(headers: {'test': 'test value'}); | ||
var copy = request.change(headers: {'test': 'new test value'}); | ||
|
||
expect(copy.headers, {'test': 'new test value', 'content-length': '0'}); | ||
}); | ||
|
||
test('new context values are added', () { | ||
var request = factory(context: {'test': 'test value'}); | ||
var copy = request.change(context: {'test2': 'test2 value'}); | ||
|
||
expect(copy.context, {'test': 'test value', 'test2': 'test2 value'}); | ||
}); | ||
|
||
test('existing context values are overwritten', () { | ||
var request = factory(context: {'test': 'test value'}); | ||
var copy = request.change(context: {'test': 'new test value'}); | ||
|
||
expect(copy.context, {'test': 'new test value'}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice to add some newlines to make the pubspec a bit more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I was figuring we just fix it up when releasing 0.12.0 into the wild
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.