feat: run GCP upload speed test as part of shorebird doctor -v (#2540)
Co-authored-by: Felix Angelov <felix@shorebird.dev>
This commit is contained in:
@@ -501,6 +501,20 @@ class CodePushClient {
|
||||
).organizations;
|
||||
}
|
||||
|
||||
/// Returns a GCP upload link for measuring upload speed.
|
||||
Future<Uri> getGCPSpeedTestUrl() async {
|
||||
final response = await _httpClient.get(
|
||||
Uri.parse('$_v1/diagnostics/gcp_upload'),
|
||||
);
|
||||
|
||||
if (!response.isSuccess) {
|
||||
throw _parseErrorResponse(response.statusCode, response.body);
|
||||
}
|
||||
|
||||
final jsonBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
return Uri.parse(jsonBody['upload_url'] as String);
|
||||
}
|
||||
|
||||
/// Closes the client.
|
||||
void close() => _httpClient.close();
|
||||
|
||||
|
||||
@@ -1978,6 +1978,50 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('getGCPSpeedTestUrl', () {
|
||||
group('when request fails', () {
|
||||
setUp(() {
|
||||
when(() => httpClient.send(any())).thenAnswer(
|
||||
(_) async => http.StreamedResponse(
|
||||
const Stream.empty(),
|
||||
HttpStatus.failedDependency,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('throws exception', () async {
|
||||
expect(
|
||||
() async => codePushClient.getGCPSpeedTestUrl(),
|
||||
throwsA(
|
||||
isA<CodePushException>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
CodePushClient.unknownErrorMessage,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('when request succeeds', () {
|
||||
setUp(() {
|
||||
when(() => httpClient.send(any())).thenAnswer(
|
||||
(_) async => http.StreamedResponse(
|
||||
Stream.value(
|
||||
utf8.encode('{"upload_url": "https://example.com"}'),
|
||||
),
|
||||
HttpStatus.ok,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns upload_url as parsed Uri', () async {
|
||||
final url = await codePushClient.getGCPSpeedTestUrl();
|
||||
expect(url, equals(Uri.parse('https://example.com')));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('close', () {
|
||||
test('closes the underlying client', () {
|
||||
codePushClient.close();
|
||||
|
||||
Reference in New Issue
Block a user