-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerTest.php
More file actions
84 lines (67 loc) · 2.88 KB
/
Copy pathDockerTest.php
File metadata and controls
84 lines (67 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
namespace Tests\Unit\Executor\Runner;
use OpenRuntimes\Executor\Runner\Docker;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;
final class DockerTest extends TestCase
{
public function testBuildCommandsUseOriginalUserCommand(): void
{
$docker = $this->createDocker();
$commands = $this->invokeGetBuildCommands($docker, 'echo original-user-command', 'v5');
$this->assertSame('bash', $commands[0]);
$this->assertStringContainsString('echo original-user-command', $commands[2]);
$this->assertStringNotContainsString('build-cache.sh', $commands[2]);
$this->assertStringNotContainsString('/cache/build-command.sh', $commands[2]);
}
public function testNoBuildCommandScriptReferenceRemains(): void
{
$docker = $this->createDocker();
foreach (['v2', 'v5'] as $version) {
$commands = $this->invokeGetBuildCommands($docker, 'echo test', $version);
$this->assertStringNotContainsString('/cache/build-command.sh', \implode(' ', $commands));
}
}
public function testNoCacheLifecycleShellCommandsAreGenerated(): void
{
$docker = $this->createDocker();
$commands = $this->invokeGetBuildCommands($docker, 'npm install', 'v5');
$command = \implode(' ', $commands);
$this->assertStringNotContainsString('restore-build-cache.sh', $command);
$this->assertStringNotContainsString('save-build-cache.sh', $command);
$this->assertStringNotContainsString('build-cache-restore.sh', $command);
$this->assertStringNotContainsString('build-cache-save.sh', $command);
}
public function testBuildCommandsReportSilentNonZeroExit(): void
{
$docker = $this->createDocker();
foreach (['v2', 'v5'] as $version) {
$commands = $this->invokeGetBuildCommands($docker, 'exit 1', $version);
$command = \implode(' ', $commands);
$this->assertStringContainsString('Build command exited with code $status.', $command);
$this->assertStringContainsString('exit $status', $command);
}
}
public function testInvalidBuildCacheKeyIsRejected(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionCode(400);
$method = new ReflectionMethod(Docker::class, 'validateBuildCacheKey');
$method->invoke($this->createDocker(), '..');
}
/**
* @return string[]
*/
private function invokeGetBuildCommands(Docker $docker, string $command, string $version): array
{
$method = new ReflectionMethod(Docker::class, 'getBuildCommands');
return $method->invoke($docker, $command, $version);
}
private function createDocker(): Docker
{
$reflection = new ReflectionClass(Docker::class);
return $reflection->newInstanceWithoutConstructor();
}
}