Support specifying a fixed list of assets on the command line (#6857)

This commit is contained in:
John McCutchan
2016-11-15 07:01:00 -08:00
committed by GitHub
parent fd5a08941e
commit d54bed45f3
5 changed files with 99 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ import 'analyze_duplicate_names_test.dart' as analyze_duplicate_names_test;
import 'analyze_test.dart' as analyze_test;
import 'android_device_test.dart' as android_device_test;
import 'android_sdk_test.dart' as android_sdk_test;
import 'asset_bundle_test.dart' as asset_bundle_test;
import 'application_package_test.dart' as application_package_test;
import 'base_utils_test.dart' as base_utils_test;
import 'channel_test.dart' as channel_test;
@@ -49,6 +50,7 @@ void main() {
android_device_test.main();
android_sdk_test.main();
application_package_test.main();
asset_bundle_test.main();
base_utils_test.main();
channel_test.main();
config_test.main();

View File

@@ -0,0 +1,60 @@
// Copyright 2016 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 'dart:io';
import 'dart:convert';
import 'package:flutter_tools/src/asset.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
void main() {
// Create a temporary directory and write a single file into it.
Directory tempDir = Directory.systemTemp.createTempSync();
String projectRoot = tempDir.path;
String assetPath = 'banana.txt';
String assetContents = 'banana';
File tempFile = new File(path.join(projectRoot, assetPath));
tempFile.parent.createSync(recursive: true);
tempFile.writeAsBytesSync(UTF8.encode(assetContents));
// Fixed asset bundle tests.
group('AssetBundle.fixed', () {
test('empty strings', () async {
expect(new AssetBundle.fixed(null, null), isNotNull);
expect(new AssetBundle.fixed('', ''), isNotNull);
expect(new AssetBundle.fixed(null, null).entries, isEmpty);
});
test('does not need a rebuild', () async {
expect(new AssetBundle.fixed(null, null).needsBuild(), isFalse);
});
test('single entry', () async {
AssetBundle ab = new AssetBundle.fixed('', 'apple.txt');
expect(ab.entries, isNotEmpty);
expect(ab.entries.length, 1);
AssetBundleEntry entry = ab.entries.first;
expect(entry, isNotNull);
expect(entry.archivePath, 'apple.txt');
});
test('two entries', () async {
AssetBundle ab = new AssetBundle.fixed('', 'apple.txt,packages/flutter_gallery_assets/shrine/products/heels.png');
expect(ab.entries, isNotEmpty);
expect(ab.entries.length, 2);
AssetBundleEntry firstEntry = ab.entries.first;
expect(firstEntry, isNotNull);
expect(firstEntry.archivePath, 'apple.txt');
AssetBundleEntry lastEntry = ab.entries.last;
expect(lastEntry, isNotNull);
expect(lastEntry.archivePath, 'packages/flutter_gallery_assets/shrine/products/heels.png');
});
test('file contents', () async {
AssetBundle ab = new AssetBundle.fixed(projectRoot, assetPath);
expect(ab.entries, isNotEmpty);
expect(ab.entries.length, 1);
AssetBundleEntry entry = ab.entries.first;
expect(entry, isNotNull);
expect(entry.archivePath, assetPath);
expect(assetContents, UTF8.decode(entry.contentsAsBytes()));
});
});
}