@@ -6,7 +6,7 @@ import { findMatchingReleaseAssetMetadata } from "../src/fetch";
66import type { ExactSemanticVersion , RepositorySlug , BinaryName , TargetTriple , TargetDuple } from "../src/types" ;
77
88// Mocked releaseMetadata for tests
9- function mockReleaseMetadata ( assets : Array < { label ?: string ; url : string } > ) {
9+ function mockReleaseMetadata ( assets : Array < { label ?: string ; name ?: string ; url : string } > ) {
1010 return {
1111 data : { assets }
1212 } ;
@@ -89,7 +89,7 @@ test("should throw error when binary name provided but no matching asset found",
8989 targetTriple ,
9090 targetDuple
9191 ) ;
92- } , new Error ( `Expected to find asset in release testowner/testrepo@v1.0.0 with label testbin-aarch64-apple-darwin or testbin-darwin-arm64` ) ) ;
92+ } , new Error ( `Expected to find asset in release testowner/testrepo@v1.0.0 with label or name testbin-aarch64-apple-darwin or testbin-darwin-arm64` ) ) ;
9393} ) ;
9494
9595// Test without binary name
@@ -147,7 +147,7 @@ test("should throw error when no binary name provided and no matching asset foun
147147 targetTriple ,
148148 targetDuple
149149 ) ;
150- } , new Error ( `Expected to find asset in release testowner/testrepo@v1.0.0 with label ending in aarch64-apple-darwin or darwin-arm64` ) ) ;
150+ } , new Error ( `Expected to find asset in release testowner/testrepo@v1.0.0 with label or name ending in aarch64-apple-darwin or darwin-arm64` ) ) ;
151151} ) ;
152152
153153test ( "should throw error when multiple assets match without binary name" , ( ) => {
@@ -227,4 +227,91 @@ test("should find x86_64 asset with binary name using target duple", () => {
227227 binaryName,
228228 url : "https://example.com/testbin-x86-duple"
229229 } ) ;
230+ } ) ;
231+
232+ // Tests for the new feature: finding assets by name property
233+ test ( "should find asset with binary name using name property with target triple" , ( ) => {
234+ const binaryName = some ( "testbin" as unknown as BinaryName ) ;
235+ const mockAssets = [
236+ // No label property, only name property
237+ { name : "testbin-aarch64-apple-darwin" , url : "https://example.com/testbin-triple" } ,
238+ ] ;
239+
240+ const result = findMatchingReleaseAssetMetadata (
241+ mockReleaseMetadata ( mockAssets ) ,
242+ mockSlug ,
243+ binaryName ,
244+ mockTag ,
245+ targetTriple ,
246+ targetDuple
247+ ) ;
248+
249+ assert . deepEqual ( result , {
250+ binaryName,
251+ url : "https://example.com/testbin-triple"
252+ } ) ;
253+ } ) ;
254+
255+ test ( "should find asset with binary name using name property with target duple" , ( ) => {
256+ const binaryName = some ( "testbin" as unknown as BinaryName ) ;
257+ const mockAssets = [
258+ // No label property, only name property
259+ { name : "testbin-darwin-arm64" , url : "https://example.com/testbin-duple" } ,
260+ ] ;
261+
262+ const result = findMatchingReleaseAssetMetadata (
263+ mockReleaseMetadata ( mockAssets ) ,
264+ mockSlug ,
265+ binaryName ,
266+ mockTag ,
267+ targetTriple ,
268+ targetDuple
269+ ) ;
270+
271+ assert . deepEqual ( result , {
272+ binaryName,
273+ url : "https://example.com/testbin-duple"
274+ } ) ;
275+ } ) ;
276+
277+ test ( "should find asset without binary name using name property with target triple" , ( ) => {
278+ const mockAssets = [
279+ // No label property, only name property
280+ { name : "somebin-aarch64-apple-darwin" , url : "https://example.com/somebin-triple" } ,
281+ ] ;
282+
283+ const result = findMatchingReleaseAssetMetadata (
284+ mockReleaseMetadata ( mockAssets ) ,
285+ mockSlug ,
286+ none ( ) ,
287+ mockTag ,
288+ targetTriple ,
289+ targetDuple
290+ ) ;
291+
292+ assert . deepEqual ( result , {
293+ binaryName : some ( "somebin" ) ,
294+ url : "https://example.com/somebin-triple"
295+ } ) ;
296+ } ) ;
297+
298+ test ( "should find asset without binary name using name property with target duple" , ( ) => {
299+ const mockAssets = [
300+ // No label property, only name property
301+ { name : "somebin-darwin-arm64" , url : "https://example.com/somebin-duple" } ,
302+ ] ;
303+
304+ const result = findMatchingReleaseAssetMetadata (
305+ mockReleaseMetadata ( mockAssets ) ,
306+ mockSlug ,
307+ none ( ) ,
308+ mockTag ,
309+ targetTriple ,
310+ targetDuple
311+ ) ;
312+
313+ assert . deepEqual ( result , {
314+ binaryName : some ( "somebin" ) ,
315+ url : "https://example.com/somebin-duple"
316+ } ) ;
230317} ) ;
0 commit comments