Reduce the chances of bots reporting analytics (#13915)

* First version

* Prevent modification of .flutter during analytics test

* Pass in directory and override analyzer warning due to conditional import

* Review comments
This commit is contained in:
jcollins-g
2018-01-05 09:38:13 -08:00
committed by GitHub
parent ad898ad03f
commit e25d881046
3 changed files with 43 additions and 16 deletions

View File

@@ -55,7 +55,7 @@ void main() {
expect(count, 0);
}, overrides: <Type, Generator>{
FlutterVersion: () => new FlutterVersion(const Clock()),
Usage: () => new Usage(),
Usage: () => new Usage(configDirOverride: temp.path),
});
// Ensure we don't send for the 'flutter config' command.
@@ -74,7 +74,7 @@ void main() {
expect(count, 0);
}, overrides: <Type, Generator>{
FlutterVersion: () => new FlutterVersion(const Clock()),
Usage: () => new Usage(),
Usage: () => new Usage(configDirOverride: temp.path),
});
});
@@ -134,6 +134,11 @@ void main() {
});
group('analytics bots', () {
Directory temp;
setUp(() {
temp = fs.systemTempDirectory.createTempSync('flutter_tools');
});
testUsingContext('don\'t send on bots', () async {
int count = 0;
flutterUsage.onSend.listen((Map<String, dynamic> data) => count++);
@@ -144,6 +149,22 @@ void main() {
Usage: () => new Usage(
settingsName: 'flutter_bot_test',
versionOverride: 'dev/unknown',
configDirOverride: temp.path,
),
});
testUsingContext('don\'t send on bots even when opted in', () async {
int count = 0;
flutterUsage.onSend.listen((Map<String, dynamic> data) => count++);
flutterUsage.enabled = true;
await createTestCommandRunner().run(<String>['--version']);
expect(count, 0);
}, overrides: <Type, Generator>{
Usage: () => new Usage(
settingsName: 'flutter_bot_test',
versionOverride: 'dev/unknown',
configDirOverride: temp.path,
),
});
});