Skip to content

Commit d2af649

Browse files
authored
Replace CLI tar use with package:tar in test utils. (#8113)
1 parent 653816e commit d2af649

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

app/test/package/backend_test_utils.dart

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ library pub_dartlang_org.backend_test_utils;
77
import 'dart:async';
88
import 'dart:io';
99

10+
import 'package:pub_dev/tool/test_profile/import_source.dart';
11+
1012
import '../shared/test_models.dart';
1113

1214
Future<T> withTempDirectory<T>(Future<T> Function(String temp) func) async {
@@ -20,37 +22,11 @@ Future<T> withTempDirectory<T>(Future<T> Function(String temp) func) async {
2022
}
2123

2224
Future<List<int>> packageArchiveBytes({required String pubspecContent}) async {
23-
return await withTempDirectory((String tmp) async {
24-
final readme = File('$tmp/README.md');
25-
final changelog = File('$tmp/CHANGELOG.md');
26-
final pubspec = File('$tmp/pubspec.yaml');
27-
final license = File('$tmp/LICENSE');
28-
29-
await readme.writeAsString(foobarReadmeContent);
30-
await changelog.writeAsString(foobarChangelogContent);
31-
await pubspec.writeAsString(pubspecContent);
32-
await license.writeAsString('BSD LICENSE 2.0');
33-
34-
await Directory('$tmp/lib').create();
35-
await File('$tmp/lib/test_library.dart')
36-
.writeAsString('hello() => print("hello");');
37-
38-
final files = [
39-
'README.md',
40-
'CHANGELOG.md',
41-
'LICENSE',
42-
'pubspec.yaml',
43-
'lib/test_library.dart'
44-
];
45-
final args = ['cz', ...files];
46-
final Process p =
47-
await Process.start('tar', args, workingDirectory: '$tmp');
48-
await p.stderr.drain();
49-
final bytes = await p.stdout.fold<List<int>>([], (b, d) => b..addAll(d));
50-
final exitCode = await p.exitCode;
51-
if (exitCode != 0) {
52-
throw Exception('Failed to make tarball of test package.');
53-
}
54-
return bytes;
55-
});
25+
final builder = ArchiveBuilder();
26+
builder.addFile('README.md', foobarReadmeContent);
27+
builder.addFile('CHANGELOG.md', foobarChangelogContent);
28+
builder.addFile('pubspec.yaml', pubspecContent);
29+
builder.addFile('LICENSE', 'BSD LICENSE 2.0');
30+
builder.addFile('lib/test_library.dart', 'hello() => print("hello");');
31+
return builder.toTarGzBytes();
5632
}

0 commit comments

Comments
 (0)