• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter_tools/src/cache.dart';
6import 'package:flutter_tools/src/commands/precache.dart';
7import 'package:flutter_tools/src/runner/flutter_command.dart';
8import 'package:flutter_tools/src/version.dart';
9import 'package:mockito/mockito.dart';
10
11import '../../src/common.dart';
12import '../../src/context.dart';
13import '../../src/mocks.dart';
14
15void main() {
16  group('precache', () {
17    final MockCache cache = MockCache();
18    Set<DevelopmentArtifact> artifacts;
19
20    when(cache.isUpToDate()).thenReturn(false);
21    when(cache.updateAll(any)).thenAnswer((Invocation invocation) {
22      artifacts = invocation.positionalArguments.first;
23      return Future<void>.value(null);
24    });
25
26    testUsingContext('Adds artifact flags to requested artifacts', () async {
27      final PrecacheCommand command = PrecacheCommand();
28      applyMocksToCommand(command);
29      await createTestCommandRunner(command).run(
30        const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows', '--fuchsia', '--flutter_runner']
31      );
32      expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
33        DevelopmentArtifact.universal,
34        DevelopmentArtifact.iOS,
35        DevelopmentArtifact.android,
36        DevelopmentArtifact.web,
37        DevelopmentArtifact.macOS,
38        DevelopmentArtifact.linux,
39        DevelopmentArtifact.windows,
40        DevelopmentArtifact.fuchsia,
41        DevelopmentArtifact.flutterRunner,
42      }));
43    }, overrides: <Type, Generator>{
44      Cache: () => cache,
45    });
46
47    final MockFlutterVersion flutterVersion = MockFlutterVersion();
48    when(flutterVersion.isMaster).thenReturn(false);
49
50    testUsingContext('Adds artifact flags to requested artifacts on stable', () async {
51      // Release lock between test cases.
52      Cache.releaseLockEarly();
53      final PrecacheCommand command = PrecacheCommand();
54      applyMocksToCommand(command);
55      await createTestCommandRunner(command).run(
56       const <String>['precache', '--ios', '--android', '--web', '--macos', '--linux', '--windows', '--fuchsia', '--flutter_runner']
57      );
58     expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
59       DevelopmentArtifact.universal,
60       DevelopmentArtifact.iOS,
61       DevelopmentArtifact.android,
62     }));
63    }, overrides: <Type, Generator>{
64      Cache: () => cache,
65      FlutterVersion: () => flutterVersion,
66    });
67
68    testUsingContext('Downloads artifacts when --force is provided', () async {
69      when(cache.isUpToDate()).thenReturn(true);
70      // Release lock between test cases.
71      Cache.releaseLockEarly();
72      final PrecacheCommand command = PrecacheCommand();
73      applyMocksToCommand(command);
74      await createTestCommandRunner(command).run(const <String>['precache', '--force']);
75      expect(artifacts, unorderedEquals(<DevelopmentArtifact>{
76       DevelopmentArtifact.universal,
77       DevelopmentArtifact.iOS,
78       DevelopmentArtifact.android,
79     }));
80    }, overrides: <Type, Generator>{
81      Cache: () => cache,
82      FlutterVersion: () => flutterVersion,
83    });
84  });
85}
86
87class MockFlutterVersion extends Mock implements FlutterVersion {}
88class MockCache extends Mock implements Cache {}
89