@@ -7,6 +7,8 @@ library pub_dartlang_org.backend_test_utils;
77import 'dart:async' ;
88import 'dart:io' ;
99
10+ import 'package:pub_dev/tool/test_profile/import_source.dart' ;
11+
1012import '../shared/test_models.dart' ;
1113
1214Future <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
2224Future <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