Skip to content

Commit 2370029

Browse files
aarondfrancisclaude
andcommitted
Add tests for Runtime and Architecture enums
Tests cover enum values, backwards compatibility with constants classes, and the runtimeValue()/architectureValue() resolution methods. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 50df4ef commit 2370029

File tree

5 files changed

+284
-0
lines changed

5 files changed

+284
-0
lines changed

tests/Unit/ArchitectureTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @author Aaron Francis <aaron@hammerstone.dev>
7+
*/
8+
9+
namespace Hammerstone\Sidecar\Tests\Unit;
10+
11+
use Hammerstone\Sidecar\Architecture;
12+
use Hammerstone\Sidecar\ArchitectureConstants;
13+
14+
class ArchitectureTest extends Base
15+
{
16+
public function test_architecture_is_a_backed_enum()
17+
{
18+
$this->assertInstanceOf(\BackedEnum::class, Architecture::X86_64);
19+
}
20+
21+
public function test_x86_64_has_correct_value()
22+
{
23+
$this->assertEquals('x86_64', Architecture::X86_64->value);
24+
}
25+
26+
public function test_arm64_has_correct_value()
27+
{
28+
$this->assertEquals('arm64', Architecture::ARM_64->value);
29+
}
30+
31+
public function test_architecture_can_be_created_from_string()
32+
{
33+
$this->assertEquals(Architecture::X86_64, Architecture::from('x86_64'));
34+
$this->assertEquals(Architecture::ARM_64, Architecture::from('arm64'));
35+
}
36+
37+
public function test_architecture_constants_class_exists_for_backwards_compatibility()
38+
{
39+
$this->assertTrue(class_exists(ArchitectureConstants::class));
40+
}
41+
42+
public function test_architecture_constants_match_enum_values()
43+
{
44+
$this->assertEquals(Architecture::X86_64->value, ArchitectureConstants::X86_64);
45+
$this->assertEquals(Architecture::ARM_64->value, ArchitectureConstants::ARM_64);
46+
}
47+
}

tests/Unit/FunctionTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* @author Aaron Francis <aaron@hammerstone.dev>
57
*/
68

79
namespace Hammerstone\Sidecar\Tests\Unit;
810

11+
use Hammerstone\Sidecar\Architecture;
12+
use Hammerstone\Sidecar\Runtime;
913
use Hammerstone\Sidecar\Tests\Unit\Support\EmptyTestFunction;
14+
use Hammerstone\Sidecar\Tests\Unit\Support\EnumRuntimeTestFunction;
15+
use Hammerstone\Sidecar\Tests\Unit\Support\StringRuntimeTestFunction;
1016

1117
class FunctionTest extends Base
1218
{
@@ -115,4 +121,73 @@ public function test_memory_and_timeout_and_storage_get_cast_to_ints()
115121
$this->assertSame(500, $array['MemorySize']);
116122
$this->assertSame(1024, $array['EphemeralStorage']['Size']);
117123
}
124+
125+
public function test_default_runtime_returns_enum()
126+
{
127+
$function = new EmptyTestFunction;
128+
129+
$this->assertInstanceOf(Runtime::class, $function->runtime());
130+
$this->assertEquals(Runtime::NODEJS_20, $function->runtime());
131+
}
132+
133+
public function test_runtime_value_resolves_enum_to_string()
134+
{
135+
$function = new EnumRuntimeTestFunction;
136+
137+
$this->assertInstanceOf(Runtime::class, $function->runtime());
138+
$this->assertEquals('python3.12', $function->runtimeValue());
139+
}
140+
141+
public function test_runtime_value_passes_through_string()
142+
{
143+
$function = new StringRuntimeTestFunction;
144+
145+
$this->assertIsString($function->runtime());
146+
$this->assertEquals('custom-runtime', $function->runtimeValue());
147+
}
148+
149+
public function test_default_architecture_from_config()
150+
{
151+
config(['sidecar.architecture' => 'arm64']);
152+
153+
$function = new EmptyTestFunction;
154+
155+
$this->assertEquals('arm64', $function->architectureValue());
156+
}
157+
158+
public function test_architecture_value_resolves_enum_to_string()
159+
{
160+
config(['sidecar.architecture' => Architecture::ARM_64]);
161+
162+
$function = new EmptyTestFunction;
163+
164+
$this->assertEquals('arm64', $function->architectureValue());
165+
}
166+
167+
public function test_architecture_value_passes_through_string()
168+
{
169+
config(['sidecar.architecture' => 'x86_64']);
170+
171+
$function = new EmptyTestFunction;
172+
173+
$this->assertEquals('x86_64', $function->architectureValue());
174+
}
175+
176+
public function test_deployment_array_contains_architecture()
177+
{
178+
config(['sidecar.architecture' => 'arm64']);
179+
180+
$function = new EmptyTestFunction;
181+
$array = $function->toDeploymentArray();
182+
183+
$this->assertEquals(['arm64'], $array['Architectures']);
184+
}
185+
186+
public function test_deployment_array_contains_runtime()
187+
{
188+
$function = new EmptyTestFunction;
189+
$array = $function->toDeploymentArray();
190+
191+
$this->assertEquals('nodejs20.x', $array['Runtime']);
192+
}
118193
}

tests/Unit/RuntimeTest.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @author Aaron Francis <aaron@hammerstone.dev>
7+
*/
8+
9+
namespace Hammerstone\Sidecar\Tests\Unit;
10+
11+
use Hammerstone\Sidecar\Runtime;
12+
use Hammerstone\Sidecar\RuntimeConstants;
13+
14+
class RuntimeTest extends Base
15+
{
16+
public function test_runtime_is_a_backed_enum()
17+
{
18+
$this->assertInstanceOf(\BackedEnum::class, Runtime::NODEJS_20);
19+
}
20+
21+
public function test_nodejs_runtimes_have_correct_values()
22+
{
23+
$this->assertEquals('nodejs24.x', Runtime::NODEJS_24->value);
24+
$this->assertEquals('nodejs22.x', Runtime::NODEJS_22->value);
25+
$this->assertEquals('nodejs20.x', Runtime::NODEJS_20->value);
26+
$this->assertEquals('nodejs18.x', Runtime::NODEJS_18->value);
27+
$this->assertEquals('nodejs16.x', Runtime::NODEJS_16->value);
28+
$this->assertEquals('nodejs14.x', Runtime::NODEJS_14->value);
29+
}
30+
31+
public function test_python_runtimes_have_correct_values()
32+
{
33+
$this->assertEquals('python3.14', Runtime::PYTHON_314->value);
34+
$this->assertEquals('python3.13', Runtime::PYTHON_313->value);
35+
$this->assertEquals('python3.12', Runtime::PYTHON_312->value);
36+
$this->assertEquals('python3.11', Runtime::PYTHON_311->value);
37+
$this->assertEquals('python3.10', Runtime::PYTHON_310->value);
38+
$this->assertEquals('python3.9', Runtime::PYTHON_39->value);
39+
$this->assertEquals('python3.8', Runtime::PYTHON_38->value);
40+
$this->assertEquals('python3.7', Runtime::PYTHON_37->value);
41+
}
42+
43+
public function test_java_runtimes_have_correct_values()
44+
{
45+
$this->assertEquals('java25', Runtime::JAVA_25->value);
46+
$this->assertEquals('java21', Runtime::JAVA_21->value);
47+
$this->assertEquals('java17', Runtime::JAVA_17->value);
48+
$this->assertEquals('java11', Runtime::JAVA_11->value);
49+
$this->assertEquals('java8.al2', Runtime::JAVA_8_LINUX2->value);
50+
$this->assertEquals('java8', Runtime::JAVA_8->value);
51+
}
52+
53+
public function test_dotnet_runtimes_have_correct_values()
54+
{
55+
$this->assertEquals('dotnet9', Runtime::DOT_NET_9->value);
56+
$this->assertEquals('dotnet8', Runtime::DOT_NET_8->value);
57+
$this->assertEquals('dotnet7', Runtime::DOT_NET_7->value);
58+
$this->assertEquals('dotnet6', Runtime::DOT_NET_6->value);
59+
}
60+
61+
public function test_ruby_runtimes_have_correct_values()
62+
{
63+
$this->assertEquals('ruby3.4', Runtime::RUBY_34->value);
64+
$this->assertEquals('ruby3.3', Runtime::RUBY_33->value);
65+
$this->assertEquals('ruby3.2', Runtime::RUBY_32->value);
66+
$this->assertEquals('ruby2.7', Runtime::RUBY_27->value);
67+
}
68+
69+
public function test_provided_runtimes_have_correct_values()
70+
{
71+
$this->assertEquals('provided.al2023', Runtime::PROVIDED_AL2023->value);
72+
$this->assertEquals('provided.al2', Runtime::PROVIDED_AL2->value);
73+
$this->assertEquals('provided', Runtime::PROVIDED->value);
74+
}
75+
76+
public function test_go_runtime_has_correct_value()
77+
{
78+
$this->assertEquals('go1.x', Runtime::GO_1X->value);
79+
}
80+
81+
public function test_runtime_can_be_created_from_string()
82+
{
83+
$this->assertEquals(Runtime::NODEJS_20, Runtime::from('nodejs20.x'));
84+
$this->assertEquals(Runtime::PYTHON_312, Runtime::from('python3.12'));
85+
}
86+
87+
public function test_runtime_constants_class_exists_for_backwards_compatibility()
88+
{
89+
$this->assertTrue(class_exists(RuntimeConstants::class));
90+
}
91+
92+
public function test_runtime_constants_match_enum_values()
93+
{
94+
$this->assertEquals(Runtime::NODEJS_24->value, RuntimeConstants::NODEJS_24);
95+
$this->assertEquals(Runtime::NODEJS_22->value, RuntimeConstants::NODEJS_22);
96+
$this->assertEquals(Runtime::NODEJS_20->value, RuntimeConstants::NODEJS_20);
97+
$this->assertEquals(Runtime::PYTHON_312->value, RuntimeConstants::PYTHON_312);
98+
$this->assertEquals(Runtime::JAVA_21->value, RuntimeConstants::JAVA_21);
99+
$this->assertEquals(Runtime::DOT_NET_8->value, RuntimeConstants::DOT_NET_8);
100+
$this->assertEquals(Runtime::RUBY_33->value, RuntimeConstants::RUBY_33);
101+
}
102+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @author Aaron Francis <aaron@hammerstone.dev>
7+
*/
8+
9+
namespace Hammerstone\Sidecar\Tests\Unit\Support;
10+
11+
use Hammerstone\Sidecar\LambdaFunction;
12+
use Hammerstone\Sidecar\Runtime;
13+
14+
class EnumRuntimeTestFunction extends LambdaFunction
15+
{
16+
public function handler()
17+
{
18+
return 'index.handler';
19+
}
20+
21+
public function package()
22+
{
23+
return [];
24+
}
25+
26+
public function runtime(): Runtime|string
27+
{
28+
return Runtime::PYTHON_312;
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @author Aaron Francis <aaron@hammerstone.dev>
7+
*/
8+
9+
namespace Hammerstone\Sidecar\Tests\Unit\Support;
10+
11+
use Hammerstone\Sidecar\LambdaFunction;
12+
use Hammerstone\Sidecar\Runtime;
13+
14+
class StringRuntimeTestFunction extends LambdaFunction
15+
{
16+
public function handler()
17+
{
18+
return 'index.handler';
19+
}
20+
21+
public function package()
22+
{
23+
return [];
24+
}
25+
26+
public function runtime(): Runtime|string
27+
{
28+
return 'custom-runtime';
29+
}
30+
}

0 commit comments

Comments
 (0)