Skip to content

Commit

Permalink
fix: asset file extension detection
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jul 20, 2024
1 parent df800ce commit e172dd9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Module/Repository/Collection/AssetsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ public function whereOperatingSystem(OperatingSystem $os): self
public function whereFileExtensions(array $extensions): self
{
return $this->filter(
static fn(AssetInterface $asset): bool => \in_array(
\pathinfo($asset->getName(), \PATHINFO_EXTENSION),
$extensions,
true,
),
static function (AssetInterface $asset) use ($extensions): bool {
$assetName = \strtolower($asset->getName());
foreach ($extensions as $extension) {
if (\str_ends_with($assetName, '.' . $extension)) {
return true;
}
}

return false;
},
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Module/Common/ArchitectureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static function provideBuildNames(): iterable
yield ['temporal_cli_0.13.2_windows_aaamd64.tar.gz', null];
yield ['temporal_cli_0.13.2_windows.amd644.tar.gz', null];
yield ['roadrunner-2024.1.5-windows.zip', null];
yield ['roadrunner-2024.1.5-linux-amd64.deb', Architecture::X86_64];
}

#[DataProvider('provideBuildNames')]
Expand Down
27 changes: 27 additions & 0 deletions tests/Unit/Module/Common/OperatingSystemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Internal\DLoad\Tests\Unit\Module\Common;

use Internal\DLoad\Module\Common\OperatingSystem;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class OperatingSystemTest extends TestCase
{
public static function provideBuildNames(): iterable
{
yield ['roadrunner-2024.1.5-windows-amd64.zip', OperatingSystem::Windows];
yield ['temporal_cli_0.13.2_windows_amd64.tar.gz', OperatingSystem::Windows];
yield ['roadrunner-2024.1.5-linux-amd64.deb', OperatingSystem::Linux];
yield ['roadrunner-2024.1.5-linux-amd64.tar.gz', OperatingSystem::Linux];
yield ['roadrunner-2024.1.5-unknown-musl-amd64.tar.gz', null];
}

#[DataProvider('provideBuildNames')]
public function testTryFromBuildName(string $name, ?OperatingSystem $expected): void
{
self::assertSame($expected, OperatingSystem::tryFromBuildName($name));
}
}

0 comments on commit e172dd9

Please sign in to comment.