-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathEnvironmentTest.php
More file actions
102 lines (98 loc) · 4.69 KB
/
Copy pathEnvironmentTest.php
File metadata and controls
102 lines (98 loc) · 4.69 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace Platformsh\Client\Tests\Model;
use Platformsh\Client\Model\Environment;
class EnvironmentTest extends \PHPUnit_Framework_TestCase
{
public function testGetSshUrl()
{
$multiApp = [
'ssh' => ['href' => 'ssh://incorrect-fallback@ssh.example.com'],
'pf:ssh:app1' => ['href' => 'ssh://projectid-envmachinename--app1@ssh.example.com'],
'pf:ssh:app2' => ['href' => 'ssh://projectid-envmachinename--app2@ssh.example.com'],
];
$haMultiAppWithInstanceDefault = [
'ssh' => ['href' => 'ssh://incorrect-fallback@ssh.example.com'],
'pf:ssh:app1' => ['href' => 'ssh://projectid-envmachinename--app1--2@ssh.example.com'],
'pf:ssh:app1:0' => ['href' => 'ssh://projectid-envmachinename--app1--0@ssh.example.com'],
'pf:ssh:app1:1' => ['href' => 'ssh://projectid-envmachinename--app1--1@ssh.example.com'],
'pf:ssh:app1:2' => ['href' => 'ssh://projectid-envmachinename--app1--2@ssh.example.com'],
'pf:ssh:app2' => ['href' => 'ssh://projectid-envmachinename--app1--2@ssh.example.com'],
'pf:ssh:app2:0' => ['href' => 'ssh://projectid-envmachinename--app2--0@ssh.example.com'],
'pf:ssh:app2:1' => ['href' => 'ssh://projectid-envmachinename--app2--1@ssh.example.com'],
'pf:ssh:app2:2' => ['href' => 'ssh://projectid-envmachinename--app2--2@ssh.example.com'],
];
$haMultiAppNoInstanceDefault = [
'ssh' => ['href' => 'ssh://incorrect-fallback@ssh.example.com'],
'pf:ssh:app1:0' => ['href' => 'ssh://projectid-envmachinename--app1--0@ssh.example.com'],
'pf:ssh:app1:1' => ['href' => 'ssh://projectid-envmachinename--app1--1@ssh.example.com'],
'pf:ssh:app1:2' => ['href' => 'ssh://projectid-envmachinename--app1--2@ssh.example.com'],
'pf:ssh:app2:0' => ['href' => 'ssh://projectid-envmachinename--app2--0@ssh.example.com'],
'pf:ssh:app2:1' => ['href' => 'ssh://projectid-envmachinename--app2--1@ssh.example.com'],
'pf:ssh:app2:2' => ['href' => 'ssh://projectid-envmachinename--app2--2@ssh.example.com'],
];
/** @var array{'_links': string[], 'app': string, 'instance': string, 'result': string|false}[] $cases */
$cases = [
[
'_links' => $multiApp,
'app' => 'app1',
'instance' => '',
'result' => 'projectid-envmachinename--app1@ssh.example.com',
],
[
'_links' => $multiApp,
'app' => 'app1',
'instance' => '1',
'result' => false,
],
[
'_links' => $haMultiAppWithInstanceDefault,
'app' => 'app1',
'instance' => '',
'result' => 'projectid-envmachinename--app1--2@ssh.example.com',
],
[
'_links' => $haMultiAppWithInstanceDefault,
'app' => 'app1',
'instance' => '0',
'result' => 'projectid-envmachinename--app1--0@ssh.example.com',
],
[
'_links' => $haMultiAppNoInstanceDefault,
'app' => 'app1',
'instance' => '',
'result' => 'projectid-envmachinename--app1--0@ssh.example.com',
],
[
'_links' => $haMultiAppNoInstanceDefault,
'app' => 'app1',
'instance' => '1',
'result' => 'projectid-envmachinename--app1--1@ssh.example.com',
],
[
'_links' => $haMultiAppNoInstanceDefault,
'app' => 'app1',
'instance' => '3',
'result' => false,
],
[
'_links' => $haMultiAppNoInstanceDefault,
'app' => 'app2',
'instance' => '',
'result' => 'projectid-envmachinename--app2--0@ssh.example.com',
],
];
foreach ($cases as $i => $case) {
$environment = new Environment(['id' => 'main', 'status' => 'active', '_links' => $case['_links']], 'https://example.com/projects/foo');
if ($case['result'] === false) {
try {
$environment->getSshUrl($case['app'], $case['instance']);
} catch (\InvalidArgumentException $e) {
$this->assertContains('SSH URL not found for instance', $e->getMessage(), "case $i");
}
continue;
}
$result = $environment->getSshUrl($case['app'], $case['instance']);
$this->assertEquals($case['result'], $result, "case $i");
}
}
}