Inject Usage dependency into FallbackDiscovery and BuildEvent (#53443)
* Usage dependency injection * Review edits
This commit is contained in:
@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/base/build.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/macos/xcode.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
@@ -189,6 +190,7 @@ void main() {
|
||||
logger: logger,
|
||||
fileSystem: fileSystem,
|
||||
terminal: Terminal.test(),
|
||||
usage: Usage.test(),
|
||||
),
|
||||
),
|
||||
artifacts: mockArtifacts,
|
||||
|
||||
@@ -8,15 +8,14 @@ import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/ios/fallback_discovery.dart';
|
||||
import 'package:flutter_tools/src/mdns_discovery.dart';
|
||||
import 'package:flutter_tools/src/protocol_discovery.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
import 'package:vm_service/vm_service.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/mocks.dart';
|
||||
|
||||
// This test still uses `testUsingContext` due to analytics usage.
|
||||
void main() {
|
||||
BufferLogger logger;
|
||||
FallbackDiscovery fallbackDiscovery;
|
||||
@@ -39,6 +38,7 @@ void main() {
|
||||
mDnsObservatoryDiscovery: mockMDnsObservatoryDiscovery,
|
||||
portForwarder: mockPortForwarder,
|
||||
protocolDiscovery: mockPrototcolDiscovery,
|
||||
flutterUsage: Usage.test(),
|
||||
vmServiceConnectUri: (String uri, {Log log}) async {
|
||||
return mockVmService;
|
||||
},
|
||||
@@ -47,7 +47,7 @@ void main() {
|
||||
.thenAnswer((Invocation invocation) async => 1);
|
||||
});
|
||||
|
||||
testUsingContext('Selects assumed port if VM service connection is successful', () async {
|
||||
testWithoutContext('Selects assumed port if VM service connection is successful', () async {
|
||||
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
|
||||
return VM.parse(<String, Object>{})..isolates = <IsolateRef>[
|
||||
IsolateRef.parse(<String, Object>{}),
|
||||
@@ -68,7 +68,7 @@ void main() {
|
||||
), Uri.parse('http://localhost:1'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects assumed port when another isolate has no root library', () async {
|
||||
testWithoutContext('Selects assumed port when another isolate has no root library', () async {
|
||||
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
|
||||
return VM.parse(<String, Object>{})..isolates = <IsolateRef>[
|
||||
IsolateRef.parse(<String, Object>{})..id = '1',
|
||||
@@ -93,7 +93,7 @@ void main() {
|
||||
), Uri.parse('http://localhost:1'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects mdns discovery if VM service connecton fails due to Sentinel', () async {
|
||||
testWithoutContext('Selects mdns discovery if VM service connecton fails due to Sentinel', () async {
|
||||
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
|
||||
return VM.parse(<String, Object>{})..isolates = <IsolateRef>[
|
||||
IsolateRef(
|
||||
@@ -124,7 +124,7 @@ void main() {
|
||||
), Uri.parse('http://localhost:1234'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects mdns discovery if VM service connecton fails', () async {
|
||||
testWithoutContext('Selects mdns discovery if VM service connecton fails', () async {
|
||||
when(mockVmService.getVM()).thenThrow(Exception());
|
||||
|
||||
when(mockMDnsObservatoryDiscovery.getObservatoryUri(
|
||||
@@ -146,7 +146,7 @@ void main() {
|
||||
), Uri.parse('http://localhost:1234'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects log scanning if both VM Service and mDNS fails', () async {
|
||||
testWithoutContext('Selects log scanning if both VM Service and mDNS fails', () async {
|
||||
when(mockVmService.getVM()).thenThrow(Exception());
|
||||
when(mockMDnsObservatoryDiscovery.getObservatoryUri(
|
||||
'hello',
|
||||
|
||||
@@ -132,7 +132,7 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
await diagnoseXcodeBuildFailure(buildResult);
|
||||
await diagnoseXcodeBuildFailure(buildResult, mockUsage, logger);
|
||||
verify(mockUsage.sendEvent('build',
|
||||
any,
|
||||
label: 'xcode-bitcode-failure',
|
||||
@@ -140,8 +140,6 @@ void main() {
|
||||
cdKey(CustomDimensions.buildEventCommand): buildCommands.toString(),
|
||||
cdKey(CustomDimensions.buildEventSettings): buildSettings.toString(),
|
||||
})).called(1);
|
||||
}, overrides: <Type, Generator>{
|
||||
Usage: () => mockUsage,
|
||||
});
|
||||
|
||||
testUsingContext('No provisioning profile shows message', () async {
|
||||
@@ -210,9 +208,9 @@ Error launching application on iPhone.''',
|
||||
),
|
||||
);
|
||||
|
||||
await diagnoseXcodeBuildFailure(buildResult);
|
||||
await diagnoseXcodeBuildFailure(buildResult, mockUsage, logger);
|
||||
expect(
|
||||
testLogger.errorText,
|
||||
logger.errorText,
|
||||
contains("No Provisioning Profile was found for your project's Bundle Identifier or your \ndevice."),
|
||||
);
|
||||
}, overrides: noColorTerminalOverride);
|
||||
@@ -291,9 +289,9 @@ Could not build the precompiled application for the device.''',
|
||||
),
|
||||
);
|
||||
|
||||
await diagnoseXcodeBuildFailure(buildResult);
|
||||
await diagnoseXcodeBuildFailure(buildResult, mockUsage, logger);
|
||||
expect(
|
||||
testLogger.errorText,
|
||||
logger.errorText,
|
||||
contains('Building a deployable iOS app requires a selected Development Team with a \nProvisioning Profile.'),
|
||||
);
|
||||
}, overrides: noColorTerminalOverride);
|
||||
@@ -328,9 +326,9 @@ Exited (sigterm)''',
|
||||
),
|
||||
);
|
||||
|
||||
await diagnoseXcodeBuildFailure(buildResult);
|
||||
await diagnoseXcodeBuildFailure(buildResult, mockUsage, logger);
|
||||
expect(
|
||||
testLogger.errorText,
|
||||
logger.errorText,
|
||||
contains('Your Xcode project requires migration.'),
|
||||
);
|
||||
}, overrides: noColorTerminalOverride);
|
||||
@@ -365,9 +363,9 @@ Exited (sigterm)''',
|
||||
),
|
||||
);
|
||||
|
||||
await diagnoseXcodeBuildFailure(buildResult);
|
||||
await diagnoseXcodeBuildFailure(buildResult, mockUsage, logger);
|
||||
expect(
|
||||
testLogger.errorText,
|
||||
logger.errorText,
|
||||
contains('Your Xcode project requires migration.'),
|
||||
);
|
||||
}, overrides: noColorTerminalOverride);
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/terminal.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/ios/xcodeproj.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
@@ -48,6 +49,7 @@ void main() {
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
terminal: terminal,
|
||||
usage: null,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -130,6 +132,7 @@ void main() {
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
terminal: terminal,
|
||||
usage: Usage.test(),
|
||||
);
|
||||
fileSystem.file(xcodebuild).deleteSync();
|
||||
|
||||
@@ -261,6 +264,7 @@ void main() {
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
terminal: terminal,
|
||||
usage: Usage.test(),
|
||||
);
|
||||
|
||||
expect(await xcodeProjectInterpreter.getInfo(workingDirectory), isNotNull);
|
||||
@@ -282,6 +286,7 @@ void main() {
|
||||
platform: platform,
|
||||
processManager: processManager,
|
||||
terminal: terminal,
|
||||
usage: Usage.test(),
|
||||
);
|
||||
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user