Skip to content
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

refactor(shorebird_code_push_api): stream engine bytes #19

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ final _engineUrl = Uri.parse(

Future<Response> downloadEngineHandler(Request request, String revision) async {
final httpClient = await request.lookup<Future<http.Client>>();
final response = await httpClient.get(
_engineUrl,
headers: {
final req = http.Request('GET', _engineUrl);
req.headers.addAll(
{
'Content-Type': 'application/octet-stream',
'Connection': 'close'
'Connection': 'close',
},
);
final response = await httpClient.send(req);

if (response.statusCode != HttpStatus.ok) {
return Response(response.statusCode, body: response.body);
return Response(response.statusCode, body: response.stream);
}

return Response.ok(response.bodyBytes);
return Response.ok(response.stream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import 'package:test/test.dart';

class _MockHttpClient extends Mock implements http.Client {}

class _FakeBaseRequest extends Fake implements http.BaseRequest {}

void main() {
group('downloadEngineHandler', () {
final uri = Uri.parse('http://localhost/');
late http.Client httpClient;

setUpAll(() {
registerFallbackValue(Uri());
registerFallbackValue(_FakeBaseRequest());
});

setUp(() {
Expand All @@ -24,8 +26,13 @@ void main() {

test('returns error on failure', () async {
when(
() => httpClient.get(any(), headers: any(named: 'headers')),
).thenAnswer((_) async => http.Response('oops', HttpStatus.unauthorized));
() => httpClient.send(any()),
).thenAnswer((_) async {
return http.StreamedResponse(
const Stream.empty(),
HttpStatus.unauthorized,
);
});
final request = Request('GET', uri).provide(() async => httpClient);

final response = await downloadEngineHandler(request, 'revision');
Expand All @@ -34,8 +41,13 @@ void main() {

test('returns bytes on success', () async {
when(
() => httpClient.get(any(), headers: any(named: 'headers')),
).thenAnswer((_) async => http.Response('OK', HttpStatus.ok));
() => httpClient.send(any()),
).thenAnswer((_) async {
return http.StreamedResponse(
const Stream.empty(),
HttpStatus.ok,
);
});
final request = Request('GET', uri).provide(() async => httpClient);

final response = await downloadEngineHandler(request, 'revision');
Expand Down