diff --git a/packages/flutter_tools/test/general.shard/ios/devices_test.dart b/packages/flutter_tools/test/general.shard/ios/devices_test.dart index 98d561de83a..84d9f6e5b81 100644 --- a/packages/flutter_tools/test/general.shard/ios/devices_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/devices_test.dart @@ -176,60 +176,6 @@ void main() { }); } - group('ios-deploy wrappers', () { - const String appId = '789'; - const String deviceId = 'device-123'; - IOSDevice device; - IOSDeploy iosDeploy; - FakeProcessManager fakeProcessManager; - const String iosDeployPath = '/path/to/ios-deploy'; - - setUp(() { - when(mockArtifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios)) - .thenReturn(iosDeployPath); - }); - - testWithoutContext('isAppInstalled() catches ProcessException from ios-deploy', () async { - final MockIOSApp mockApp = MockIOSApp(); - when(mockApp.id).thenReturn(appId); - fakeProcessManager = FakeProcessManager.list([ - FakeCommand( - command: const [ - iosDeployPath, - '--id', - deviceId, - '--exists', - '--bundle_id', - appId, - ], - onRun: () => throw const ProcessException('ios-deploy', []), - ) - ]); - iosDeploy = IOSDeploy( - artifacts: mockArtifacts, - cache: mockCache, - logger: logger, - platform: macPlatform, - processManager: fakeProcessManager, - ); - device = IOSDevice( - deviceId, - artifacts: mockArtifacts, - fileSystem: mockFileSystem, - logger: logger, - platform: macPlatform, - iosDeploy: iosDeploy, - iMobileDevice: iMobileDevice, - name: 'iPhone 1', - sdkVersion: '13.3', - cpuArchitecture: DarwinArch.arm64, - ); - - final bool result = await device.isAppInstalled(mockApp); - expect(result, false); - }); - }); - group('.dispose()', () { IOSDevice device; MockIOSApp appPackage1; diff --git a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart index 57cc81e05bd..677fb8b2c05 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart @@ -2,11 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io' show Process; - import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/base/logger.dart'; -import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/ios/ios_deploy.dart'; import 'package:mockito/mockito.dart'; @@ -14,105 +11,87 @@ import 'package:platform/platform.dart'; import 'package:process/process.dart'; import '../../src/common.dart'; -import '../../src/mocks.dart'; +import '../../src/context.dart'; + +void main () { + testWithoutContext('IOSDeploy.iosDeployEnv returns path with /usr/bin first', () { + final IOSDeploy iosDeploy = setUpIOSDeploy(FakeProcessManager.any()); + final Map environment = iosDeploy.iosDeployEnv; + + expect(environment['PATH'], startsWith('/usr/bin')); + }); + + testWithoutContext('IOSDeploy.uninstallApp calls ios-deploy with correct arguments and returns 0 on success', () async { + const String deviceId = '123'; + const String bundleId = 'com.example.app'; + final FakeProcessManager processManager = FakeProcessManager.list([ + const FakeCommand(command: [ + 'ios-deploy', + '--id', + deviceId, + '--uninstall_only', + '--bundle_id', + bundleId, + ]) + ]); + final IOSDeploy iosDeploy = setUpIOSDeploy(processManager); + final int exitCode = await iosDeploy.uninstallApp( + deviceId: deviceId, + bundleId: bundleId, + ); + + expect(exitCode, 0); + expect(processManager.hasRemainingExpectations, false); + }); + + testWithoutContext('IOSDeploy.uninstallApp returns non-zero exit code when ios-deploy does the same', () async { + const String deviceId = '123'; + const String bundleId = 'com.example.app'; + final FakeProcessManager processManager = FakeProcessManager.list([ + const FakeCommand(command: [ + 'ios-deploy', + '--id', + deviceId, + '--uninstall_only', + '--bundle_id', + bundleId, + ], exitCode: 1) + ]); + final IOSDeploy iosDeploy = setUpIOSDeploy(processManager); + final int exitCode = await iosDeploy.uninstallApp( + deviceId: deviceId, + bundleId: bundleId, + ); + + expect(exitCode, 1); + expect(processManager.hasRemainingExpectations, false); + }); +} + +IOSDeploy setUpIOSDeploy(ProcessManager processManager) { + const MapEntry kDyLdLibEntry = MapEntry( + 'DYLD_LIBRARY_PATH', '/path/to/libs', + ); + final FakePlatform macPlatform = FakePlatform( + operatingSystem: 'macos', + environment: { + 'PATH': '/usr/local/bin:/usr/bin' + } + ); + final MockArtifacts artifacts = MockArtifacts(); + final MockCache cache = MockCache(); + + when(cache.dyLdLibEntry).thenReturn(kDyLdLibEntry); + when(artifacts.getArtifactPath(Artifact.iosDeploy, platform: anyNamed('platform'))) + .thenReturn('ios-deploy'); + return IOSDeploy( + logger: BufferLogger.test(), + platform: macPlatform, + processManager: processManager, + artifacts: artifacts, + cache: cache, + ); +} class MockArtifacts extends Mock implements Artifacts {} class MockCache extends Mock implements Cache {} -class MockPlatform extends Mock implements Platform {} -class MockProcess extends Mock implements Process {} -class MockProcessManager extends Mock implements ProcessManager {} - -void main () { - group('IOSDeploy()', () { - Artifacts mockArtifacts; - Cache mockCache; - IOSDeploy iosDeploy; - Logger logger; - Platform mockPlatform; - ProcessManager mockProcessManager; - const String iosDeployPath = '/path/to/ios-deploy'; - const String deviceId = '123'; - const String bundleId = 'com.example.app'; - - setUp(() { - mockArtifacts = MockArtifacts(); - when(mockArtifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios)) - .thenReturn(iosDeployPath); - mockCache = MockCache(); - const MapEntry mapEntry = MapEntry('DYLD_LIBRARY_PATH', '/path/to/libs'); - when(mockCache.dyLdLibEntry).thenReturn(mapEntry); - logger = BufferLogger.test(); - mockPlatform = MockPlatform(); - when(mockPlatform.environment).thenReturn({ - 'PATH': '/usr/local/bin:/usr/bin', - }); - mockProcessManager = MockProcessManager(); - iosDeploy = IOSDeploy( - artifacts: mockArtifacts, - cache: mockCache, - logger: logger, - platform: mockPlatform, - processManager: mockProcessManager, - ); - }); - - testWithoutContext('iosDeployEnv returns path with /usr/bin first', () { - final Map env = iosDeploy.iosDeployEnv; - expect(env['PATH'].startsWith('/usr/bin'), true); - }); - - testWithoutContext('uninstallApp() calls ios-deploy with correct arguments and returns 0 on success', () async { - final List args = [ - iosDeployPath, - '--id', - deviceId, - '--uninstall_only', - '--bundle_id', - bundleId, - ]; - when(mockProcessManager.start( - args, - workingDirectory: anyNamed('workingDirectory'), - environment: anyNamed('environment'), - )).thenAnswer((Invocation invocation) => Future.value(createMockProcess(exitCode: 0))); - final int exitCode = await iosDeploy.uninstallApp( - deviceId: deviceId, - bundleId: bundleId, - ); - - verify(mockProcessManager.start( - args, - workingDirectory: anyNamed('workingDirectory'), - environment: anyNamed('environment'), - )); - expect(exitCode, 0); - }); - - testWithoutContext('uninstallApp() returns non-zero exit code when ios-deploy does the same', () async { - final List args = [ - iosDeployPath, - '--id', - deviceId, - '--uninstall_only', - '--bundle_id', - bundleId, - ]; - when(mockProcessManager.start( - args, - workingDirectory: anyNamed('workingDirectory'), - environment: anyNamed('environment'), - )).thenAnswer((Invocation invocation) => Future.value(createMockProcess(exitCode: 1))); - final int exitCode = await iosDeploy.uninstallApp( - deviceId: deviceId, - bundleId: bundleId, - ); - - verify(mockProcessManager.start( - args, - workingDirectory: anyNamed('workingDirectory'), - environment: anyNamed('environment'), - )); - expect(exitCode, 1); - }); - }); -}