utils_test.dart 2.29 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2019 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/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/utils.dart';
import 'package:platform/platform.dart';

10 11 12
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/mocks.dart';
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

void main() {
  group('BotDetector', () {
    FakePlatform fakePlatform;
    MockStdio mockStdio;
    BotDetector botDetector;

    setUp(() {
      fakePlatform = FakePlatform()..environment = <String, String>{};
      mockStdio = MockStdio();
      botDetector = const BotDetector();
    });

    group('isRunningOnBot', () {
      testUsingContext('returns false unconditionally if BOT=false is set', () async {
        fakePlatform.environment['BOT'] = 'false';
        fakePlatform.environment['TRAVIS'] = 'true';
        expect(botDetector.isRunningOnBot, isFalse);
      }, overrides: <Type, Generator>{
        Stdio: () => mockStdio,
        Platform: () => fakePlatform,
      });

      testUsingContext('returns false unconditionally if FLUTTER_HOST is set', () async {
        fakePlatform.environment['FLUTTER_HOST'] = 'foo';
        fakePlatform.environment['TRAVIS'] = 'true';
        expect(botDetector.isRunningOnBot, isFalse);
      }, overrides: <Type, Generator>{
        Stdio: () => mockStdio,
        Platform: () => fakePlatform,
      });

45
      testUsingContext('returns false with and without a terminal attached', () async {
46 47 48
        mockStdio.stdout.hasTerminal = true;
        expect(botDetector.isRunningOnBot, isFalse);
        mockStdio.stdout.hasTerminal = false;
49
        expect(botDetector.isRunningOnBot, isFalse);
50 51 52 53
      }, overrides: <Type, Generator>{
        Stdio: () => mockStdio,
        Platform: () => fakePlatform,
      });
54 55 56 57 58 59 60 61 62

      testUsingContext('can test analytics outputs on bots when outputting to a file', () async {
        fakePlatform.environment['TRAVIS'] = 'true';
        fakePlatform.environment['FLUTTER_ANALYTICS_LOG_FILE'] = '/some/file';
        expect(botDetector.isRunningOnBot, isFalse);
      }, overrides: <Type, Generator>{
        Stdio: () => mockStdio,
        Platform: () => fakePlatform,
      });
63 64 65
    });
  });
}