-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the JS serverless plugin
- Loading branch information
Showing
4 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
service: bref | ||
provider: | ||
name: aws | ||
runtime: php-83 | ||
|
||
plugins: | ||
- ../../index.js | ||
|
||
functions: | ||
function: | ||
handler: function.php | ||
function-arm: | ||
handler: function.php | ||
architecture: arm64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
service: bref | ||
provider: | ||
name: aws | ||
|
||
plugins: | ||
- ../../index.js | ||
|
||
functions: | ||
function: | ||
handler: function.php | ||
runtime: php-83 | ||
fpm: | ||
handler: fpm.php | ||
runtime: php-83-fpm | ||
console: | ||
handler: console.php | ||
runtime: php-83-console | ||
|
||
function-arm: | ||
handler: function.php | ||
architecture: arm64 | ||
runtime: php-83 | ||
fpm-arm: | ||
handler: fpm.php | ||
architecture: arm64 | ||
runtime: php-83-fpm | ||
console-arm: | ||
handler: console.php | ||
architecture: arm64 | ||
runtime: php-83-console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Bref\Test; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Process\Process; | ||
use Symfony\Component\Yaml\Yaml; | ||
|
||
class PluginTest extends TestCase | ||
{ | ||
public function test the plugin adds the layers(): void | ||
{ | ||
$output = $this->slsPrint('serverless.yml'); | ||
|
||
self::assertFunction($output['functions']['function'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:php-83:', | ||
]); | ||
self::assertFunction($output['functions']['fpm'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:php-83-fpm:', | ||
]); | ||
self::assertFunction($output['functions']['console'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:php-83:', | ||
'arn:aws:lambda:us-east-1:534081306603:layer:console:', | ||
]); | ||
|
||
self::assertFunction($output['functions']['function-arm'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83:', | ||
]); | ||
self::assertFunction($output['functions']['fpm-arm'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83-fpm:', | ||
]); | ||
self::assertFunction($output['functions']['console-arm'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83:', | ||
'arn:aws:lambda:us-east-1:534081306603:layer:console:', | ||
]); | ||
} | ||
|
||
public function test the plugin adds the layers when the runtime is set in the provider(): void | ||
{ | ||
$output = $this->slsPrint('serverless-runtime-root.yml'); | ||
|
||
self::assertFunction($output['functions']['function'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:php-83:', | ||
]); | ||
self::assertFunction($output['functions']['function-arm'], 'provided.al2', [ | ||
'arn:aws:lambda:us-east-1:534081306603:layer:arm-php-83:', | ||
]); | ||
} | ||
|
||
private function slsPrint(string $configFile): array | ||
{ | ||
$process = (new Process( | ||
['serverless', 'print', '-c', $configFile], | ||
cwd: __DIR__ . '/Plugin', | ||
env: [ | ||
'SLS_TELEMETRY_DISABLED' => '1', // else we sometimes get HTTP errors (and its faster) | ||
], | ||
))->mustRun(); | ||
return Yaml::parse($process->getOutput()); | ||
} | ||
|
||
private static function assertFunction(array $config, string $runtime, array $layers): void | ||
{ | ||
self::assertEquals($runtime, $config['runtime']); | ||
self::assertCount(count($layers), $config['layers']); | ||
foreach ($layers as $index => $layer) { | ||
self::assertStringStartsWith($layer, $config['layers'][$index]); | ||
} | ||
} | ||
} |