Files
sdk/pkg/dds/test/dds_exception_parsing_test.dart
T
Ben Konyi dbe6d5852a Fix bad pattern matching in DDS exception parsing
Nullable types for values in map patterns require the key to be present. Since the 'uri' key is not always present in DDS exception responses, this was causing us to fall back to throwing a StateError.

Related issue: https://github.com/flutter/flutter/issues/152684

Change-Id: I929e1e880c4fc6f740ee595e6e852f23fa247b92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378600
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
2024-08-01 20:03:34 +00:00

57 lines
2.0 KiB
Dart

// Copyright 2024 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:dds/dds.dart';
import 'package:test/test.dart';
void main() {
group('DartDevelopmentServiceException.fromJson', () {
test('parses existing DDS instance error', () {
final actual = DartDevelopmentServiceException.fromJson(
<String, Object>{
'error_code':
DartDevelopmentServiceException.existingDdsInstanceError,
'message': 'Foo',
'uri': 'http://localhost',
},
);
final expected = DartDevelopmentServiceException.existingDdsInstance(
'Foo',
ddsUri: Uri.parse('http://localhost'),
);
expect(actual.errorCode, expected.errorCode);
expect(actual.message, expected.message);
expect(actual, isA<ExistingDartDevelopmentServiceException>());
expect(
(actual as ExistingDartDevelopmentServiceException).ddsUri,
(expected as ExistingDartDevelopmentServiceException).ddsUri,
);
});
test('parses connection issue error', () {
final actual = DartDevelopmentServiceException.fromJson(
<String, Object>{
'error_code': DartDevelopmentServiceException.connectionError,
'message': 'Foo',
},
);
final expected = DartDevelopmentServiceException.connectionIssue('Foo');
expect(actual.errorCode, expected.errorCode);
expect(actual.message, expected.message);
});
test('parses failed to start error', () {
final expected = DartDevelopmentServiceException.failedToStart();
final actual = DartDevelopmentServiceException.fromJson(
<String, Object>{
'error_code': DartDevelopmentServiceException.failedToStartError,
'message': expected.message,
},
);
expect(actual.errorCode, expected.errorCode);
expect(actual.message, expected.message);
});
});
}