Commit 18fcb91e authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Add tests for iOS doctor validaton (#7794)

parent b082b93a
......@@ -38,6 +38,8 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
String get iosDeployVersionText => runSync(<String>['ios-deploy', '--version']).replaceAll('\n', '');
bool get hasHomebrew => os.which('brew') != null;
bool get _iosDeployIsInstalledAndMeetsVersionCheck {
if (!hasIosDeploy)
return false;
......@@ -89,7 +91,7 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
}
// brew installed
if (os.which('brew') != null) {
if (hasHomebrew) {
brewStatus = ValidationType.installed;
if (!exitsHappy(<String>['ideviceinstaller', '-h'])) {
......@@ -132,9 +134,13 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
}
return new ValidationResult(
xcodeStatus == brewStatus ? xcodeStatus : ValidationType.partial,
<ValidationType>[xcodeStatus, brewStatus].reduce(_mergeValidationTypes),
messages,
statusInfo: xcodeVersionInfo
);
}
ValidationType _mergeValidationTypes(ValidationType t1, ValidationType t2) {
return t1 == t2 ? t1 : ValidationType.partial;
}
}
// Copyright 2017 The Chromium 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:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/ios/ios_workflow.dart';
import 'package:flutter_tools/src/ios/mac.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import '../context.dart';
void main() {
group('iOS Workflow validation', () {
MockXCode xcode;
setUp(() {
xcode = new MockXCode();
});
testUsingContext('Emit missing status when nothing is installed', () async {
when(xcode.isInstalled).thenReturn(false);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget()
..hasHomebrew = false
..hasIosDeploy = false;
ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.missing);
}, overrides: <Type, Generator>{ XCode: () => xcode });
testUsingContext('Emits partial status when Xcode is not installed', () async {
when(xcode.isInstalled).thenReturn(false);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget();
ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{ XCode: () => xcode });
testUsingContext('Emits partial status when Xcode version too low', () async {
when(xcode.isInstalled).thenReturn(true);
when(xcode.xcodeVersionText)
.thenReturn('Xcode 7.0.1\nBuild version 7C1002\n');
when(xcode.isInstalledAndMeetsVersionCheck).thenReturn(false);
when(xcode.eulaSigned).thenReturn(true);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget();
ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{ XCode: () => xcode });
testUsingContext('Emits partial status when Xcode EULA not signed', () async {
when(xcode.isInstalled).thenReturn(true);
when(xcode.xcodeVersionText)
.thenReturn('Xcode 8.2.1\nBuild version 8C1002\n');
when(xcode.isInstalledAndMeetsVersionCheck).thenReturn(true);
when(xcode.eulaSigned).thenReturn(false);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget();
ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{ XCode: () => xcode });
testUsingContext('Emits partial status when homebrew not installed', () async {
when(xcode.isInstalled).thenReturn(true);
when(xcode.xcodeVersionText)
.thenReturn('Xcode 8.2.1\nBuild version 8C1002\n');
when(xcode.isInstalledAndMeetsVersionCheck).thenReturn(true);
when(xcode.eulaSigned).thenReturn(true);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget()
..hasHomebrew = false;
ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{ XCode: () => xcode });
testUsingContext('Emits partial status when ios-deploy is not installed', () async {
when(xcode.isInstalled).thenReturn(true);
when(xcode.xcodeVersionText)
.thenReturn('Xcode 8.2.1\nBuild version 8C1002\n');
when(xcode.isInstalledAndMeetsVersionCheck).thenReturn(true);
when(xcode.eulaSigned).thenReturn(true);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget()
..hasIosDeploy = false;
ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{ XCode: () => xcode });
testUsingContext('Emits partial status when ios-deploy version is too low', () async {
when(xcode.isInstalled).thenReturn(true);
when(xcode.xcodeVersionText)
.thenReturn('Xcode 8.2.1\nBuild version 8C1002\n');
when(xcode.isInstalledAndMeetsVersionCheck).thenReturn(true);
when(xcode.eulaSigned).thenReturn(true);
IOSWorkflowTestTarget workflow = new IOSWorkflowTestTarget()
..iosDeployVersionText = '1.8.0';
ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
}, overrides: <Type, Generator>{ XCode: () => xcode });
testUsingContext('Succeeds when all checks pass', () async {
when(xcode.isInstalled).thenReturn(true);
when(xcode.xcodeVersionText)
.thenReturn('Xcode 8.2.1\nBuild version 8C1002\n');
when(xcode.isInstalledAndMeetsVersionCheck).thenReturn(true);
when(xcode.eulaSigned).thenReturn(true);
ValidationResult result = await new IOSWorkflowTestTarget().validate();
expect(result.type, ValidationType.installed);
}, overrides: <Type, Generator>{ XCode: () => xcode });
});
}
class MockXCode extends Mock implements XCode {}
class IOSWorkflowTestTarget extends IOSWorkflow {
@override
bool hasHomebrew = true;
@override
bool hasIosDeploy = true;
@override
String iosDeployVersionText = '1.9.0';
}
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