|
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | 5 | import 'package:logging/logging.dart'; |
| 6 | +import 'package:path/path.dart' as p; |
6 | 7 | import 'package:pub_dev/search/search_service.dart'; |
| 8 | +import 'package:pub_dev/search/updater.dart'; |
7 | 9 | import 'package:pub_dev/service/entrypoint/_isolate.dart'; |
8 | 10 | import 'package:pub_dev/service/entrypoint/search_index.dart'; |
| 11 | +import 'package:pub_dev/shared/utils.dart'; |
9 | 12 | import 'package:test/test.dart'; |
10 | 13 |
|
11 | 14 | final _logger = Logger('search_index_test'); |
12 | 15 |
|
13 | 16 | void main() { |
14 | 17 | group('Search index inside an isolate', () { |
15 | | - final indexRunner = IsolateRunner.uri( |
16 | | - kind: 'index', |
17 | | - logger: _logger, |
18 | | - spawnUri: |
19 | | - Uri.parse('package:pub_dev/service/entrypoint/search_index.dart'), |
20 | | - ); |
21 | | - |
22 | | - tearDownAll(() async { |
| 18 | + late IsolateRunner indexRunner; |
| 19 | + |
| 20 | + tearDown(() async { |
23 | 21 | await indexRunner.close(); |
24 | 22 | }); |
25 | 23 |
|
26 | | - test('start and work with index', () async { |
27 | | - await indexRunner.start(1); |
| 24 | + test('start and work with local index', () async { |
| 25 | + await withTempDirectory((tempDir) async { |
| 26 | + final snapshotPath = p.join(tempDir.path, 'index.json.gz'); |
| 27 | + await saveInMemoryPackageIndexToFile( |
| 28 | + [ |
| 29 | + PackageDocument( |
| 30 | + package: 'json_annotation', |
| 31 | + description: 'Annotation metadata for JSON serialization.', |
| 32 | + ), |
| 33 | + ], |
| 34 | + snapshotPath, |
| 35 | + ); |
| 36 | + |
| 37 | + indexRunner = IsolateRunner.uri( |
| 38 | + kind: 'index', |
| 39 | + logger: _logger, |
| 40 | + spawnUri: |
| 41 | + Uri.parse('package:pub_dev/service/entrypoint/search_index.dart'), |
| 42 | + spawnArgs: ['--snapshot', snapshotPath], |
| 43 | + ); |
| 44 | + |
| 45 | + await indexRunner.start(1); |
28 | 46 |
|
29 | | - // index calling the sendport |
30 | | - final searchIndex = IsolateSearchIndex(indexRunner); |
31 | | - expect(await searchIndex.isReady(), true); |
| 47 | + // index calling the sendport |
| 48 | + final searchIndex = IsolateSearchIndex(indexRunner); |
| 49 | + expect(await searchIndex.isReady(), true); |
32 | 50 |
|
33 | | - // working search only with SDK results (no packages in the isolate) |
34 | | - final rs = |
35 | | - await searchIndex.search(ServiceSearchQuery.parse(query: 'json')); |
36 | | - expect(rs.errorMessage, isNull); |
37 | | - expect(rs.sdkLibraryHits, isEmpty); |
38 | | - expect(rs.packageHits, isEmpty); |
| 51 | + // returns package hit |
| 52 | + final rs = |
| 53 | + await searchIndex.search(ServiceSearchQuery.parse(query: 'json')); |
| 54 | + expect(rs.toJson(), { |
| 55 | + 'timestamp': isNotEmpty, |
| 56 | + 'totalCount': 1, |
| 57 | + 'sdkLibraryHits': [], |
| 58 | + 'packageHits': [ |
| 59 | + { |
| 60 | + 'package': 'json_annotation', |
| 61 | + 'score': greaterThan(0.5), |
| 62 | + }, |
| 63 | + ], |
| 64 | + }); |
| 65 | + }); |
39 | 66 | }, timeout: Timeout(Duration(minutes: 5))); |
40 | 67 | }); |
41 | 68 | } |
0 commit comments