|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Validates command to deploy to a Cloud Foundry. |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\Deployment\Tests\Command\CloudFoundry; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\Deployment\Command\CloudFoundry\DeployCommand; |
|
9
|
|
|
use Graviton\Deployment\Configuration; |
|
10
|
|
|
use Graviton\Deployment\Deployment; |
|
11
|
|
|
use Graviton\Deployment\DeployScriptsTestCase; |
|
12
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
13
|
|
|
use Symfony\Component\Config\FileLocator; |
|
14
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author List of contributors <https://github.com/libgraviton/deploy-scripts/graphs/contributors> |
|
18
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
19
|
|
|
* @link http://swisscom.ch |
|
20
|
|
|
*/ |
|
21
|
|
|
class DeployCommandTest extends DeployScriptsTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @dataProvider deployData |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $appName name of app |
|
27
|
|
|
* @param string $appVersion version to deploy |
|
28
|
|
|
* @param string $expected output to expect from cf |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testDeploy($appName, $appVersion, $expected) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->configYamlExists(); |
|
35
|
|
|
$this->suppressOutput(); |
|
36
|
|
|
|
|
37
|
|
|
$locator = new FileLocator(__DIR__.'/../../Resources/config'); |
|
38
|
|
|
$configuration = new Configuration(new Processor(), $locator); |
|
39
|
|
|
$deploymentHandler = new Deployment(new ProcessBuilder()); |
|
40
|
|
|
|
|
41
|
|
|
$application = $this->getSetUpApplication(new DeployCommand($deploymentHandler, $configuration)); |
|
42
|
|
|
$command = $application->find('graviton:deployment:cf:deploy'); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals( |
|
45
|
|
|
$expected, |
|
46
|
|
|
$this->getOutputFromCommand($command, ['applicationName' => $appName, 'versionName' => $appVersion]) |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return array[] |
|
52
|
|
|
*/ |
|
53
|
|
|
public function deployData() |
|
54
|
|
|
{ |
|
55
|
|
|
$expectedUnstable = <<<"EOD" |
|
56
|
|
|
Deploying application (graviton-unstable) to a Cloud Foundry instance. |
|
57
|
|
|
Trying to login... done |
|
58
|
|
|
Determining which application slice to be deployed |
|
59
|
|
|
... done |
|
60
|
|
|
Trying to find deployment slice (blue)... found. Using slice graviton-unstable-green as deployment target. |
|
61
|
|
|
Will deploy application: graviton-unstable-green. |
|
62
|
|
|
Pushing graviton-unstable-green to Cloud Foundry. |
|
63
|
|
|
... done |
|
64
|
|
|
|
|
65
|
|
|
Creating services... done |
|
66
|
|
|
cs mongodb free graviton-unstable-mongodb |
|
67
|
|
|
bind-service graviton-unstable-green graviton-unstable-mongodb |
|
68
|
|
|
cs mongodb free graviton-unstable-test |
|
69
|
|
|
bind-service graviton-unstable-green graviton-unstable-test |
|
70
|
|
|
|
|
71
|
|
|
Defining environment variables... done |
|
72
|
|
|
set-env graviton-unstable-green ERRBIT_API_KEY some_secret_key |
|
73
|
|
|
|
|
74
|
|
|
Starting application (graviton-unstable). |
|
75
|
|
|
... done |
|
76
|
|
|
|
|
77
|
|
|
Adding route (graviton-unstable) to application (graviton-unstable). |
|
78
|
|
|
... done |
|
79
|
|
|
|
|
80
|
|
|
Removing graviton-unstable-blue from Cloud Foundry.... done |
|
81
|
|
|
unmap-route graviton-unstable-blue DOMAIN -n graviton-unstable |
|
82
|
|
|
stop graviton-unstable-blue |
|
83
|
|
|
delete graviton-unstable-blue -f |
|
84
|
|
|
|
|
85
|
|
|
Logging out... bye |
|
86
|
|
|
|
|
87
|
|
|
EOD; |
|
88
|
|
|
$expectedMaster = <<<"EOD" |
|
89
|
|
|
Deploying application (graviton-master) to a Cloud Foundry instance. |
|
90
|
|
|
Trying to login... done |
|
91
|
|
|
Determining which application slice to be deployed |
|
92
|
|
|
... done |
|
93
|
|
|
Trying to find deployment slice (blue)... found. Using slice graviton-master-green as deployment target. |
|
94
|
|
|
Will deploy application: graviton-master-green. |
|
95
|
|
|
Pushing graviton-master-green to Cloud Foundry. |
|
96
|
|
|
... done |
|
97
|
|
|
|
|
98
|
|
|
Creating services... done |
|
99
|
|
|
cs mongodb free graviton-master-mongodb |
|
100
|
|
|
bind-service graviton-master-green graviton-master-mongodb |
|
101
|
|
|
cs mongodb free graviton-master-test |
|
102
|
|
|
bind-service graviton-master-green graviton-master-test |
|
103
|
|
|
|
|
104
|
|
|
Defining environment variables... done |
|
105
|
|
|
set-env graviton-master-green ERRBIT_API_KEY some_secret_key |
|
106
|
|
|
|
|
107
|
|
|
Starting application (graviton-master). |
|
108
|
|
|
... done |
|
109
|
|
|
|
|
110
|
|
|
Adding route (graviton) to application (graviton-master). |
|
111
|
|
|
... done |
|
112
|
|
|
|
|
113
|
|
|
Removing graviton-master-blue from Cloud Foundry.... done |
|
114
|
|
|
unmap-route graviton-master-blue DOMAIN -n graviton |
|
115
|
|
|
stop graviton-master-blue |
|
116
|
|
|
delete graviton-master-blue -f |
|
117
|
|
|
|
|
118
|
|
|
Logging out... bye |
|
119
|
|
|
|
|
120
|
|
|
EOD; |
|
121
|
|
|
|
|
122
|
|
|
return [ |
|
123
|
|
|
'unstable deploy' => [ |
|
124
|
|
|
'graviton', |
|
125
|
|
|
'unstable', |
|
126
|
|
|
$expectedUnstable, |
|
127
|
|
|
], |
|
128
|
|
|
'master deploy' => [ |
|
129
|
|
|
'graviton', |
|
130
|
|
|
'master', |
|
131
|
|
|
$expectedMaster, |
|
132
|
|
|
], |
|
133
|
|
|
]; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|