Replace MockConfig with TestConfig (#75044)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../convert.dart';
|
||||
@@ -38,11 +39,16 @@ class Config {
|
||||
|
||||
/// Constructs a new [Config] object from a file called [name] in
|
||||
/// the given [Directory].
|
||||
factory Config.test(
|
||||
String name, {
|
||||
@required Directory directory,
|
||||
@required Logger logger,
|
||||
}) => Config.createForTesting(directory.childFile('.${kConfigDir}_$name'), logger);
|
||||
///
|
||||
/// Defaults to [BufferLogger], [MemoryFileSystem], and [name]=test.
|
||||
factory Config.test({
|
||||
String name = 'test',
|
||||
Directory directory,
|
||||
Logger logger,
|
||||
}) {
|
||||
directory ??= MemoryFileSystem.test().directory('/');
|
||||
return Config.createForTesting(directory.childFile('.${kConfigDir}_$name'), logger ?? BufferLogger.test());
|
||||
}
|
||||
|
||||
/// Test only access to the Config constructor.
|
||||
@visibleForTesting
|
||||
|
||||
@@ -76,7 +76,7 @@ class _DefaultPersistentToolState implements PersistentToolState {
|
||||
@required Directory directory,
|
||||
@required Logger logger,
|
||||
}) : _config = Config.test(
|
||||
_kFileName,
|
||||
name: _kFileName,
|
||||
directory: directory,
|
||||
logger: logger,
|
||||
);
|
||||
|
||||
@@ -35,12 +35,12 @@ void main() {
|
||||
|
||||
group('analytics', () {
|
||||
Directory tempDir;
|
||||
MockFlutterConfig mockFlutterConfig;
|
||||
Config testConfig;
|
||||
|
||||
setUp(() {
|
||||
Cache.flutterRoot = '../..';
|
||||
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_tools_analytics_test.');
|
||||
mockFlutterConfig = MockFlutterConfig();
|
||||
testConfig = Config.test();
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
@@ -105,8 +105,7 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('Usage records one feature in experiment setting', () async {
|
||||
when<bool>(mockFlutterConfig.getValue(flutterWebFeature.configSetting) as bool)
|
||||
.thenReturn(true);
|
||||
testConfig.setValue(flutterWebFeature.configSetting, true);
|
||||
final Usage usage = Usage(runningOnBot: true);
|
||||
usage.sendCommand('test');
|
||||
|
||||
@@ -115,7 +114,7 @@ void main() {
|
||||
expect(globals.fs.file('test').readAsStringSync(), contains('$featuresKey: enable-web'));
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
|
||||
Config: () => mockFlutterConfig,
|
||||
Config: () => testConfig,
|
||||
Platform: () => FakePlatform(environment: <String, String>{
|
||||
'FLUTTER_ANALYTICS_LOG_FILE': 'test',
|
||||
}),
|
||||
@@ -124,12 +123,9 @@ void main() {
|
||||
});
|
||||
|
||||
testUsingContext('Usage records multiple features in experiment setting', () async {
|
||||
when<bool>(mockFlutterConfig.getValue(flutterWebFeature.configSetting) as bool)
|
||||
.thenReturn(true);
|
||||
when<bool>(mockFlutterConfig.getValue(flutterLinuxDesktopFeature.configSetting) as bool)
|
||||
.thenReturn(true);
|
||||
when<bool>(mockFlutterConfig.getValue(flutterMacOSDesktopFeature.configSetting) as bool)
|
||||
.thenReturn(true);
|
||||
testConfig.setValue(flutterWebFeature.configSetting, true);
|
||||
testConfig.setValue(flutterLinuxDesktopFeature.configSetting, true);
|
||||
testConfig.setValue(flutterMacOSDesktopFeature.configSetting, true);
|
||||
final Usage usage = Usage(runningOnBot: true);
|
||||
usage.sendCommand('test');
|
||||
|
||||
@@ -141,7 +137,7 @@ void main() {
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
|
||||
Config: () => mockFlutterConfig,
|
||||
Config: () => testConfig,
|
||||
Platform: () => FakePlatform(environment: <String, String>{
|
||||
'FLUTTER_ANALYTICS_LOG_FILE': 'test',
|
||||
}),
|
||||
@@ -370,8 +366,6 @@ class FakeFlutterCommand extends FlutterCommand {
|
||||
|
||||
class MockDoctor extends Mock implements Doctor {}
|
||||
|
||||
class MockFlutterConfig extends Mock implements Config {}
|
||||
|
||||
class FakeClock extends Fake implements SystemClock {
|
||||
List<int> times = <int>[];
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/android/android_sdk.dart';
|
||||
import 'package:flutter_tools/src/base/config.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart' show ProcessResult;
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -29,11 +28,7 @@ void main() {
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
processManager = MockProcessManager();
|
||||
config = Config.test(
|
||||
'test',
|
||||
directory: fileSystem.currentDirectory,
|
||||
logger: BufferLogger.test(),
|
||||
);
|
||||
config = Config.test();
|
||||
});
|
||||
|
||||
group('android_sdk AndroidSdk', () {
|
||||
|
||||
@@ -9,7 +9,6 @@ import 'package:flutter_tools/src/android/android_studio_validator.dart';
|
||||
import 'package:flutter_tools/src/base/config.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/user_messages.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
@@ -36,11 +35,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('NoAndroidStudioValidator shows Android Studio as "not available" when not available.', () async {
|
||||
final Config config = Config.test(
|
||||
'test',
|
||||
directory: fileSystem.currentDirectory,
|
||||
logger: BufferLogger.test(),
|
||||
);
|
||||
final Config config = Config.test();
|
||||
final NoAndroidStudioValidator validator = NoAndroidStudioValidator(
|
||||
config: config,
|
||||
platform: linuxPlatform,
|
||||
|
||||
@@ -15,20 +15,23 @@ import '../src/common.dart';
|
||||
void main() {
|
||||
group('Features', () {
|
||||
MockFlutterVerion mockFlutterVerion;
|
||||
MockFlutterConfig mockFlutterConfig;
|
||||
Config testConfig;
|
||||
MockPlatform mockPlatform;
|
||||
FlutterFeatureFlags featureFlags;
|
||||
|
||||
setUp(() {
|
||||
mockFlutterVerion = MockFlutterVerion();
|
||||
mockFlutterConfig = MockFlutterConfig();
|
||||
testConfig = Config.test();
|
||||
mockPlatform = MockPlatform();
|
||||
when(mockPlatform.environment).thenReturn(<String, String>{});
|
||||
when<bool>(mockFlutterConfig.getValue(any) as bool).thenReturn(false);
|
||||
|
||||
for (final Feature feature in allFeatures) {
|
||||
testConfig.setValue(feature.configSetting, false);
|
||||
}
|
||||
|
||||
featureFlags = FlutterFeatureFlags(
|
||||
flutterVersion: mockFlutterVerion,
|
||||
config: mockFlutterConfig,
|
||||
config: testConfig,
|
||||
platform: mockPlatform,
|
||||
);
|
||||
});
|
||||
@@ -129,7 +132,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter web enabled with config on master', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('master');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-web') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-web', true);
|
||||
|
||||
expect(featureFlags.isWebEnabled, true);
|
||||
});
|
||||
@@ -149,7 +152,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter web enabled with config on dev', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('dev');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-web') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-web', true);
|
||||
|
||||
expect(featureFlags.isWebEnabled, true);
|
||||
});
|
||||
@@ -169,7 +172,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter web enabled with config on beta', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('beta');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-web') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-web', true);
|
||||
|
||||
expect(featureFlags.isWebEnabled, true);
|
||||
});
|
||||
@@ -183,14 +186,14 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter web on by default on stable', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('stable');
|
||||
when<bool>(mockFlutterConfig.getValue(any) as bool).thenReturn(null);
|
||||
testConfig.removeValue('enable-web');
|
||||
|
||||
expect(featureFlags.isWebEnabled, true);
|
||||
});
|
||||
|
||||
testWithoutContext('flutter web enabled with config on stable', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('stable');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-web') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-web', true);
|
||||
|
||||
expect(featureFlags.isWebEnabled, true);
|
||||
});
|
||||
@@ -212,7 +215,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter macos desktop enabled with config on master', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('master');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-macos-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-macos-desktop', true);
|
||||
|
||||
expect(featureFlags.isMacOSEnabled, true);
|
||||
});
|
||||
@@ -232,7 +235,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter macos desktop enabled with config on dev', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('dev');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-macos-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-macos-desktop', true);
|
||||
|
||||
expect(featureFlags.isMacOSEnabled, true);
|
||||
});
|
||||
@@ -252,7 +255,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter macos desktop enabled with config on beta', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('beta');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-macos-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-macos-desktop', true);
|
||||
|
||||
expect(featureFlags.isMacOSEnabled, true);
|
||||
});
|
||||
@@ -272,7 +275,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter macos desktop enabled with config on stable', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('stable');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-macos-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-macos-desktop', true);
|
||||
|
||||
expect(featureFlags.isMacOSEnabled, true);
|
||||
});
|
||||
@@ -293,7 +296,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter linux desktop enabled with config on master', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('master');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-linux-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-linux-desktop', true);
|
||||
|
||||
expect(featureFlags.isLinuxEnabled, true);
|
||||
});
|
||||
@@ -313,7 +316,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter linux desktop enabled with config on dev', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('dev');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-linux-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-linux-desktop', true);
|
||||
|
||||
expect(featureFlags.isLinuxEnabled, true);
|
||||
});
|
||||
@@ -333,7 +336,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter linux desktop enabled with config on beta', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('beta');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-linux-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-linux-desktop', true);
|
||||
|
||||
expect(featureFlags.isLinuxEnabled, true);
|
||||
});
|
||||
@@ -353,7 +356,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter linux desktop enabled with config on stable', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('stable');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-linux-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-linux-desktop', true);
|
||||
|
||||
expect(featureFlags.isLinuxEnabled, true);
|
||||
});
|
||||
@@ -374,7 +377,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter windows desktop enabled with config on master', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('master');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-windows-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-windows-desktop', true);
|
||||
|
||||
expect(featureFlags.isWindowsEnabled, true);
|
||||
});
|
||||
@@ -394,7 +397,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter windows desktop enabled with config on dev', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('dev');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-windows-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-windows-desktop', true);
|
||||
|
||||
expect(featureFlags.isWindowsEnabled, true);
|
||||
});
|
||||
@@ -414,7 +417,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter windows desktop enabled with config on beta', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('beta');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-windows-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-windows-desktop', true);
|
||||
|
||||
expect(featureFlags.isWindowsEnabled, true);
|
||||
});
|
||||
@@ -434,7 +437,7 @@ void main() {
|
||||
|
||||
testWithoutContext('flutter windows desktop enabled with config on stable', () {
|
||||
when(mockFlutterVerion.channel).thenReturn('stable');
|
||||
when<bool>(mockFlutterConfig.getValue('enable-windows-desktop') as bool).thenReturn(true);
|
||||
testConfig.setValue('enable-windows-desktop', true);
|
||||
|
||||
expect(featureFlags.isWindowsEnabled, true);
|
||||
});
|
||||
@@ -449,7 +452,6 @@ void main() {
|
||||
}
|
||||
|
||||
class MockFlutterVerion extends Mock implements FlutterVersion {}
|
||||
class MockFlutterConfig extends Mock implements Config {}
|
||||
class MockPlatform extends Mock implements Platform {}
|
||||
|
||||
T nonconst<T>(T item) => item;
|
||||
|
||||
@@ -25,7 +25,7 @@ import '../../src/mocks.dart';
|
||||
void main() {
|
||||
group('Auto signing', () {
|
||||
ProcessManager mockProcessManager;
|
||||
Config mockConfig;
|
||||
Config testConfig;
|
||||
IosProject mockIosProject;
|
||||
BuildableIOSApp app;
|
||||
AnsiTerminal testTerminal;
|
||||
@@ -36,7 +36,7 @@ void main() {
|
||||
mockProcessManager = MockProcessManager();
|
||||
// Assume all binaries exist and are executable
|
||||
when(mockProcessManager.canRun(any)).thenReturn(true);
|
||||
mockConfig = MockConfig();
|
||||
testConfig = Config.test();
|
||||
mockIosProject = MockIosProject();
|
||||
when(mockIosProject.buildSettingsForBuildInfo(any)).thenAnswer((_) {
|
||||
return Future<Map<String, String>>.value(<String, String>{
|
||||
@@ -343,10 +343,10 @@ void main() {
|
||||
verify(mockOpenSslStdIn.write('This is a mock certificate'));
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '4444DDDD44'});
|
||||
|
||||
verify(globals.config.setValue('ios-signing-cert', 'iPhone Developer: Profile 3 (3333CCCC33)'));
|
||||
expect(testConfig.getValue('ios-signing-cert'), 'iPhone Developer: Profile 3 (3333CCCC33)');
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Config: () => mockConfig,
|
||||
Config: () => testConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
@@ -426,7 +426,7 @@ void main() {
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '5555EEEE55'});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Config: () => mockConfig,
|
||||
Config: () => testConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
@@ -486,7 +486,7 @@ void main() {
|
||||
));
|
||||
when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
|
||||
when(mockOpenSslProcess.exitCode).thenAnswer((_) => Future<int>.value(0));
|
||||
when<String>(mockConfig.getValue('ios-signing-cert') as String).thenReturn('iPhone Developer: Profile 3 (3333CCCC33)');
|
||||
testConfig.setValue('ios-signing-cert', 'iPhone Developer: Profile 3 (3333CCCC33)');
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
@@ -508,7 +508,7 @@ void main() {
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '4444DDDD44'});
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Config: () => mockConfig,
|
||||
Config: () => testConfig,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
});
|
||||
|
||||
@@ -570,7 +570,7 @@ void main() {
|
||||
));
|
||||
when(mockOpenSslProcess.stderr).thenAnswer((Invocation invocation) => mockOpenSslStdErr);
|
||||
when(mockOpenSslProcess.exitCode).thenAnswer((_) => Future<int>.value(0));
|
||||
when<String>(mockConfig.getValue('ios-signing-cert') as String).thenReturn('iPhone Developer: Invalid Profile');
|
||||
testConfig.setValue('ios-signing-cert', 'iPhone Developer: Invalid Profile');
|
||||
|
||||
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
|
||||
iosApp: app,
|
||||
@@ -588,10 +588,10 @@ void main() {
|
||||
contains('Certificate choice "iPhone Developer: Profile 3 (3333CCCC33)"'),
|
||||
);
|
||||
expect(signingConfigs, <String, String>{'DEVELOPMENT_TEAM': '4444DDDD44'});
|
||||
verify(globals.config.setValue('ios-signing-cert', 'iPhone Developer: Profile 3 (3333CCCC33)'));
|
||||
expect(testConfig.getValue('ios-signing-cert'), 'iPhone Developer: Profile 3 (3333CCCC33)');
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Config: () => mockConfig,
|
||||
Config: () => testConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
});
|
||||
|
||||
@@ -667,7 +667,7 @@ void main() {
|
||||
expect(signingConfigs, isNull);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Config: () => mockConfig,
|
||||
Config: () => testConfig,
|
||||
AnsiTerminal: () => testTerminal,
|
||||
});
|
||||
});
|
||||
@@ -691,7 +691,6 @@ class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockProcess extends Mock implements Process {}
|
||||
class MockStream extends Mock implements Stream<List<int>> {}
|
||||
class MockStdIn extends Mock implements IOSink {}
|
||||
class MockConfig extends Mock implements Config {}
|
||||
|
||||
Stream<String> mockTerminalStdInStream;
|
||||
|
||||
|
||||
@@ -174,18 +174,12 @@ Hello!
|
||||
}
|
||||
|
||||
FlutterTesterDevices setUpFlutterTesterDevices() {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Logger logger = BufferLogger.test();
|
||||
return FlutterTesterDevices(
|
||||
logger: logger,
|
||||
logger: BufferLogger.test(),
|
||||
artifacts: Artifacts.test(),
|
||||
processManager: FakeProcessManager.any(),
|
||||
fileSystem: MemoryFileSystem.test(),
|
||||
config: Config.test(
|
||||
'test',
|
||||
directory: fileSystem.currentDirectory,
|
||||
logger: logger,
|
||||
),
|
||||
config: Config.test(),
|
||||
flutterVersion: MockFlutterVersion(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ void testUsingContext(
|
||||
'flutter_config_dir_test.',
|
||||
);
|
||||
return Config.test(
|
||||
Config.kFlutterSettings,
|
||||
name: Config.kFlutterSettings,
|
||||
directory: configDir,
|
||||
logger: globals.logger,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user