fuchsia_workflow_test.dart 5.62 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:file/memory.dart';
6
import 'package:flutter_tools/src/base/file_system.dart';
7
import 'package:flutter_tools/src/base/platform.dart';
8
import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart';
9 10
import 'package:flutter_tools/src/fuchsia/fuchsia_workflow.dart';

11
import '../../src/common.dart';
12
import '../../src/fakes.dart';
13 14

void main() {
15 16 17
  final FileSystem fileSystem = MemoryFileSystem.test();
  final File devFinder = fileSystem.file('dev_finder');
  final File sshConfig = fileSystem.file('ssh_config');
18
  final File ffx = fileSystem.file('ffx');
19 20 21

  testWithoutContext('Fuchsia workflow does not apply to host platform if feature is disabled', () {
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
22
      featureFlags: TestFeatureFlags(isFuchsiaEnabled: false),
23
      fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
24
      platform: FakePlatform(operatingSystem: 'linux'),
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    );

    expect(fuchsiaWorkflow.appliesToHostPlatform, false);
  });

  testWithoutContext('Fuchsia workflow does not apply to host platform on Windows', () {
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(isFuchsiaEnabled: true),
      fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
      platform: FakePlatform(operatingSystem: 'windows'),
    );

    expect(fuchsiaWorkflow.appliesToHostPlatform, false);
  });

40
  testWithoutContext('Fuchsia workflow can not list and launch devices if there is no ffx when using default workflow', () {
41 42
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(),
43 44
      fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: null),
      platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
45 46 47 48 49 50 51
    );

    expect(fuchsiaWorkflow.canLaunchDevices, false);
    expect(fuchsiaWorkflow.canListDevices, false);
    expect(fuchsiaWorkflow.canListEmulators, false);
  });

52
  testWithoutContext('Fuchsia workflow can not list and launch devices if there is no dev finder when ffx is disabled', () {
53 54
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(),
55 56
      fuchsiaArtifacts: FuchsiaArtifacts(devFinder: null, sshConfig: sshConfig, ffx: ffx),
      platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
57 58 59 60 61 62 63 64 65 66
    );

    expect(fuchsiaWorkflow.canLaunchDevices, false);
    expect(fuchsiaWorkflow.canListDevices, false);
    expect(fuchsiaWorkflow.canListEmulators, false);
  });

  testWithoutContext('Fuchsia workflow can not launch devices if there is no ssh config when using default workflow', () {
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(),
67 68
      fuchsiaArtifacts: FuchsiaArtifacts(sshConfig: null, ffx: ffx),
      platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
69 70 71 72 73 74 75
    );

    expect(fuchsiaWorkflow.canLaunchDevices, false);
    expect(fuchsiaWorkflow.canListDevices, true);
    expect(fuchsiaWorkflow.canListEmulators, false);
  });

76
  testWithoutContext('Fuchsia workflow can not launch devices if there is no ssh config when ffx is disabled', () {
77 78
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(),
79 80
      fuchsiaArtifacts: FuchsiaArtifacts(sshConfig: null, devFinder: devFinder),
      platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
81 82 83 84 85 86 87 88 89 90
    );

    expect(fuchsiaWorkflow.canLaunchDevices, false);
    expect(fuchsiaWorkflow.canListDevices, true);
    expect(fuchsiaWorkflow.canListEmulators, false);
  });

  testWithoutContext('Fuchsia workflow can list and launch devices supported with sufficient SDK artifacts when using default workflow', () {
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(),
91 92
      fuchsiaArtifacts: FuchsiaArtifacts(devFinder: null, sshConfig: sshConfig, ffx: ffx),
      platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
93 94 95 96 97 98 99 100 101 102
    );

    expect(fuchsiaWorkflow.canLaunchDevices, true);
    expect(fuchsiaWorkflow.canListDevices, true);
    expect(fuchsiaWorkflow.canListEmulators, false);
  });

  testWithoutContext('Fuchsia workflow can list and launch devices supported with sufficient SDK artifacts when ffx is disabled', () {
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(),
103 104
      fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: null),
      platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
105 106 107 108 109 110 111 112 113 114
    );

    expect(fuchsiaWorkflow.canLaunchDevices, true);
    expect(fuchsiaWorkflow.canListDevices, true);
    expect(fuchsiaWorkflow.canListEmulators, false);
  });

  testWithoutContext('Fuchsia workflow can list and launch devices supported with sufficient SDK artifacts on macOS', () {
    final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
      featureFlags: TestFeatureFlags(),
115 116
      fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
      platform: FakePlatform(operatingSystem: 'macOS', environment: <String, String>{}),
117 118 119 120 121
    );

    expect(fuchsiaWorkflow.canLaunchDevices, true);
    expect(fuchsiaWorkflow.canListDevices, true);
    expect(fuchsiaWorkflow.canListEmulators, false);
122 123
  });
}