ios_deploy_test.dart 3.18 KB
Newer Older
1 2 3 4 5 6
// Copyright 2014 The Flutter 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/artifacts.dart';
import 'package:flutter_tools/src/base/logger.dart';
7
import 'package:flutter_tools/src/base/platform.dart';
8 9 10 11 12 13
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/ios/ios_deploy.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';

import '../../src/common.dart';
14
import '../../src/context.dart';
15 16

void main () {
17 18 19
  testWithoutContext('IOSDeploy.iosDeployEnv returns path with /usr/bin first', () {
    final IOSDeploy iosDeploy = setUpIOSDeploy(FakeProcessManager.any());
    final Map<String, String> environment = iosDeploy.iosDeployEnv;
20

21 22
    expect(environment['PATH'], startsWith('/usr/bin'));
  });
23

24 25 26 27 28 29
  testWithoutContext('IOSDeploy.uninstallApp calls ios-deploy with correct arguments and returns 0 on success', () async {
    const String deviceId = '123';
    const String bundleId = 'com.example.app';
    final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
      const FakeCommand(command: <String>[
        'ios-deploy',
30 31 32 33 34
        '--id',
        deviceId,
        '--uninstall_only',
        '--bundle_id',
        bundleId,
35 36 37 38 39 40 41
      ])
    ]);
    final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
    final int exitCode = await iosDeploy.uninstallApp(
      deviceId: deviceId,
      bundleId: bundleId,
    );
42

43 44 45
    expect(exitCode, 0);
    expect(processManager.hasRemainingExpectations, false);
  });
46

47 48 49 50 51 52
  testWithoutContext('IOSDeploy.uninstallApp returns non-zero exit code when ios-deploy does the same', () async {
    const String deviceId = '123';
    const String bundleId = 'com.example.app';
    final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
      const FakeCommand(command: <String>[
        'ios-deploy',
53 54 55 56 57
        '--id',
        deviceId,
        '--uninstall_only',
        '--bundle_id',
        bundleId,
58 59 60 61 62 63 64
      ], exitCode: 1)
    ]);
    final IOSDeploy iosDeploy = setUpIOSDeploy(processManager);
    final int exitCode = await iosDeploy.uninstallApp(
      deviceId: deviceId,
      bundleId: bundleId,
    );
65

66 67
    expect(exitCode, 1);
    expect(processManager.hasRemainingExpectations, false);
68 69
  });
}
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

IOSDeploy setUpIOSDeploy(ProcessManager processManager) {
  const MapEntry<String, String> kDyLdLibEntry = MapEntry<String, String>(
    'DYLD_LIBRARY_PATH', '/path/to/libs',
  );
  final FakePlatform macPlatform = FakePlatform(
    operatingSystem: 'macos',
    environment: <String, String>{
      'PATH': '/usr/local/bin:/usr/bin'
    }
  );
  final MockArtifacts artifacts = MockArtifacts();
  final MockCache cache = MockCache();

  when(cache.dyLdLibEntry).thenReturn(kDyLdLibEntry);
  when(artifacts.getArtifactPath(Artifact.iosDeploy, platform: anyNamed('platform')))
    .thenReturn('ios-deploy');
  return IOSDeploy(
    logger: BufferLogger.test(),
    platform: macPlatform,
    processManager: processManager,
    artifacts: artifacts,
    cache: cache,
  );
}

class MockArtifacts extends Mock implements Artifacts {}
class MockCache extends Mock implements Cache {}