@@ -82,6 +82,17 @@ void main() async {
82
82
},
83
83
},
84
84
],
85
+ if (hookType == 'link' )
86
+ 'assets_from_linking' : [
87
+ {
88
+ 'type' : 'code_assets/code' ,
89
+ 'encoding' : {
90
+ 'file' : 'not there' ,
91
+ 'id' : 'package:my_package/name2' ,
92
+ 'link_mode' : {'type' : 'dynamic_loading_bundle' },
93
+ },
94
+ },
95
+ ],
85
96
'config' : {
86
97
'build_asset_types' : ['code_assets/code' ],
87
98
'extensions' : {'code_assets' : codeConfig},
@@ -94,6 +105,27 @@ void main() async {
94
105
};
95
106
}
96
107
108
+ // Full JSON to see where the config sits in the full JSON.
109
+ // When removing the non-hierarchical JSON, we can change this test to only
110
+ // check the nested key.
111
+ Map <String , Object > linkOutputJson () => {
112
+ 'assets' : [
113
+ {'some_key' : 'some_value' , 'type' : 'some_asset_type' },
114
+ {'some_other_key' : 'some_value' , 'type' : 'some_other_asset_type' },
115
+ ],
116
+ 'assets_for_linking' : {
117
+ 'package_with_linker' : [
118
+ {
119
+ 'encoding' : {'key' : 'foo' , 'value' : 'bar' },
120
+ 'type' : 'hooks/metadata' ,
121
+ },
122
+ ],
123
+ },
124
+ 'dependencies' : ['/assets/data_2.json' , '/assets/data_3.json' ],
125
+ 'status' : 'success' ,
126
+ 'timestamp' : '2025-02-11 11:20:20.000' ,
127
+ };
128
+
97
129
void expectCorrectCodeConfig (
98
130
CodeConfig codeCondig, {
99
131
OS targetOS = OS .android,
@@ -168,7 +200,18 @@ void main() async {
168
200
outputFile: outFile,
169
201
outputDirectoryShared: outputDirectoryShared,
170
202
)
171
- ..setupLink (assets: assets, recordedUsesFile: null )
203
+ ..setupLink (
204
+ assets: assets,
205
+ recordedUsesFile: null ,
206
+ assetsFromLinking: [
207
+ CodeAsset (
208
+ name: 'name2' ,
209
+ package: 'my_package' ,
210
+ file: Uri .file ('not there' ),
211
+ linkMode: DynamicLoadingBundled (),
212
+ ).encode (),
213
+ ],
214
+ )
172
215
..addExtension (
173
216
CodeAssetExtension (
174
217
targetOS: OS .android,
@@ -282,12 +325,54 @@ void main() async {
282
325
]).remove ('link_mode' );
283
326
expect (
284
327
() => LinkInput (input).assets.code.first.linkMode,
328
+ throwsA (
329
+ predicate (
330
+ (e) =>
331
+ e is FormatException &&
332
+ e.message.contains ("""
333
+ No value was provided for 'assets.0.encoding.link_mode'.""" ),
334
+ ),
335
+ ),
336
+ );
337
+ });
338
+
339
+ test ('LinkInput.assets_from_linking.0.encoding.link_mode missing' , () {
340
+ final input = inputJson (hookType: 'link' );
341
+ traverseJson <Map <String , Object ?>>(input, [
342
+ 'assets_from_linking' ,
343
+ 0 ,
344
+ 'encoding' ,
345
+ ]).remove ('link_mode' );
346
+ expect (
347
+ () =>
348
+ LinkInput (input).assets.assetsFromLinking.first.asCodeAsset.linkMode,
349
+ throwsA (
350
+ predicate (
351
+ (e) =>
352
+ e is FormatException &&
353
+ e.message.contains ("""
354
+ No value was provided for 'assets_from_linking.0.encoding.link_mode'.""" ),
355
+ ),
356
+ ),
357
+ );
358
+ });
359
+
360
+ test ('LinkOutput.assets_for_linking.package_with_linker.0.type missing' , () {
361
+ final input = linkOutputJson ();
362
+ traverseJson <Map <String , Object ?>>(input, [
363
+ 'assets_for_linking' ,
364
+ 'package_with_linker' ,
365
+ 0 ,
366
+ ]).remove ('type' );
367
+ expect (
368
+ () =>
369
+ LinkOutput (input).assets.encodedAssetsForLink.values.first.first.type,
285
370
throwsA (
286
371
predicate (
287
372
(e) =>
288
373
e is FormatException &&
289
374
e.message.contains (
290
- "No value was provided for 'assets .0.encoding.link_mode '." ,
375
+ "No value was provided for 'package_with_linker .0.type '." ,
291
376
),
292
377
),
293
378
),
0 commit comments