Unverified Commit c5800fe1 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] update iOS deploy tests for best practices (#53343)

parent 8afc67f7
......@@ -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>[
FakeCommand(
command: const <String>[
iosDeployPath,
'--id',
deviceId,
'--exists',
'--bundle_id',
appId,
],
onRun: () => throw const ProcessException('ios-deploy', <String>[]),
)
]);
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;
......
......@@ -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';
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 {}
import '../../src/context.dart';
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<String, String> mapEntry = MapEntry<String, String>('DYLD_LIBRARY_PATH', '/path/to/libs');
when(mockCache.dyLdLibEntry).thenReturn(mapEntry);
logger = BufferLogger.test();
mockPlatform = MockPlatform();
when(mockPlatform.environment).thenReturn(<String, String>{
'PATH': '/usr/local/bin:/usr/bin',
});
mockProcessManager = MockProcessManager();
iosDeploy = IOSDeploy(
artifacts: mockArtifacts,
cache: mockCache,
logger: logger,
platform: mockPlatform,
processManager: mockProcessManager,
);
});
testWithoutContext('IOSDeploy.iosDeployEnv returns path with /usr/bin first', () {
final IOSDeploy iosDeploy = setUpIOSDeploy(FakeProcessManager.any());
final Map<String, String> environment = iosDeploy.iosDeployEnv;
testWithoutContext('iosDeployEnv returns path with /usr/bin first', () {
final Map<String, String> env = iosDeploy.iosDeployEnv;
expect(env['PATH'].startsWith('/usr/bin'), true);
});
expect(environment['PATH'], startsWith('/usr/bin'));
});
testWithoutContext('uninstallApp() calls ios-deploy with correct arguments and returns 0 on success', () async {
final List<String> args = <String>[
iosDeployPath,
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(<FakeCommand>[
const FakeCommand(command: <String>[
'ios-deploy',
'--id',
deviceId,
'--uninstall_only',
'--bundle_id',
bundleId,
];
when(mockProcessManager.start(
args,
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((Invocation invocation) => Future<Process>.value(createMockProcess(exitCode: 0)));
final int exitCode = await iosDeploy.uninstallApp(
deviceId: deviceId,
bundleId: bundleId,
);
])
]);
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
final int exitCode = await iosDeploy.uninstallApp(
deviceId: deviceId,
bundleId: bundleId,
);
verify(mockProcessManager.start(
args,
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
));
expect(exitCode, 0);
});
expect(exitCode, 0);
expect(processManager.hasRemainingExpectations, false);
});
testWithoutContext('uninstallApp() returns non-zero exit code when ios-deploy does the same', () async {
final List<String> args = <String>[
iosDeployPath,
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(<FakeCommand>[
const FakeCommand(command: <String>[
'ios-deploy',
'--id',
deviceId,
'--uninstall_only',
'--bundle_id',
bundleId,
];
when(mockProcessManager.start(
args,
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenAnswer((Invocation invocation) => Future<Process>.value(createMockProcess(exitCode: 1)));
final int exitCode = await iosDeploy.uninstallApp(
deviceId: deviceId,
bundleId: bundleId,
);
], exitCode: 1)
]);
final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
final int exitCode = await iosDeploy.uninstallApp(
deviceId: deviceId,
bundleId: bundleId,
);
verify(mockProcessManager.start(
args,
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
));
expect(exitCode, 1);
});
expect(exitCode, 1);
expect(processManager.hasRemainingExpectations, false);
});
}
IOSDeploy setUpIOSDeploy(ProcessManager processManager) {
const MapEntry<String, String> kDyLdLibEntry = MapEntry<String, String>(
'DYLD_LIBRARY_PATH', '/path/to/libs',
);
final FakePlatform macPlatform = FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{
'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 {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment