Skip to content

Commit e714665

Browse files
committed
Fixing apiExporter's scope.
1 parent b4cbf70 commit e714665

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

app/test/package/api_export/api_exporter_test.dart

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:googleapis/storage/v1.dart' show DetailedApiRequestError;
1313
import 'package:logging/logging.dart';
1414
import 'package:pub_dev/fake/backend/fake_auth_provider.dart';
1515
import 'package:pub_dev/package/api_export/api_exporter.dart';
16-
import 'package:pub_dev/shared/datastore.dart';
16+
import 'package:pub_dev/shared/configuration.dart';
1717
import 'package:pub_dev/shared/storage.dart';
1818
import 'package:pub_dev/shared/utils.dart';
1919
import 'package:pub_dev/shared/versions.dart';
@@ -49,15 +49,19 @@ void main() {
4949
'SHOUT Deleting object from public bucket: "packages/bar-2.0.0.tar.gz".',
5050
'SHOUT Deleting object from public bucket: "packages/bar-3.0.0.tar.gz".',
5151
], (fakeTime) async {
52-
await storageService.createBucket('bucket');
53-
final bucket = storageService.bucket('bucket');
54-
final apiExporter =
55-
ApiExporter(dbService, storageService: storageService, bucket: bucket);
52+
// Since we want to verify post-upload tasks triggering API exporter,
53+
// we cannot use an isolated instance, we need to use the same setup.
54+
// However, for better control and consistency, we can remove all the
55+
// existing files from the bucket at the start of this test:
56+
await apiExporter!.stop();
57+
final bucket =
58+
storageService.bucket(activeConfiguration.exportedApiBucketName!);
59+
await _deleteAll(bucket);
5660

5761
await _testExportedApiSynchronization(
5862
fakeTime,
5963
bucket,
60-
apiExporter.synchronizeExportedApi,
64+
apiExporter!.synchronizeExportedApi,
6165
);
6266
});
6367

@@ -69,26 +73,38 @@ void main() {
6973
],
7074
testProfile: _testProfile,
7175
(fakeTime) async {
72-
await storageService.createBucket('bucket');
73-
final bucket = storageService.bucket('bucket');
74-
final apiExporter = ApiExporter(dbService,
75-
storageService: storageService, bucket: bucket);
76+
// Since we want to verify post-upload tasks triggering API exporter,
77+
// we cannot use an isolated instance, we need to use the same setup.
78+
// However, for better control and consistency, we can remove all the
79+
// existing files from the bucket at the start of this test:
80+
await apiExporter!.stop();
81+
final bucket =
82+
storageService.bucket(activeConfiguration.exportedApiBucketName!);
83+
await _deleteAll(bucket);
7684

77-
await apiExporter.synchronizeExportedApi();
85+
await apiExporter!.synchronizeExportedApi();
7886

79-
await apiExporter.start();
87+
await apiExporter!.start();
8088

8189
await _testExportedApiSynchronization(
8290
fakeTime,
8391
bucket,
8492
() async => await fakeTime.elapse(minutes: 15),
8593
);
8694

87-
await apiExporter.stop();
95+
await apiExporter!.stop();
8896
},
8997
);
9098
}
9199

100+
Future<void> _deleteAll(Bucket bucket) async {
101+
await for (final entry in bucket.list(delimiter: '')) {
102+
if (entry.isObject) {
103+
await bucket.delete(entry.name);
104+
}
105+
}
106+
}
107+
92108
Future<void> _testExportedApiSynchronization(
93109
FakeTime fakeTime,
94110
Bucket bucket,

0 commit comments

Comments
 (0)