This repository has been archived by the owner on Oct 16, 2019. It is now read-only.
/
ElasticIpTest.php
227 lines (196 loc) · 8.25 KB
/
ElasticIpTest.php
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Service
*/
namespace ZendTest\Service\Amazon\Ec2;
use Zend\Service\Amazon\Ec2;
/**
* Zend_Service_Amazon_Ec2_Elasticip test case.
*
* @category Zend
* @package Zend_Service_Amazon
* @subpackage UnitTests
* @group Zend_Service
* @group Zend_Service_Amazon
* @group Zend_Service_Amazon_Ec2
*/
class ElasticIpTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Zend_Service_Amazon_Ec2_Elasticip
*/
private $elasticip;
/**
* Prepares the environment before running a test.
*/
protected function setUp()
{
$this->elasticip = new Ec2\ElasticIp('access_key', 'secret_access_key');
$adapter = new \Zend\Http\Client\Adapter\Test();
$client = new \Zend\Http\Client(null, array(
'adapter' => $adapter
));
$this->adapter = $adapter;
Ec2\ElasticIp::setDefaultHTTPClient($client);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
unset($this->adapter);
$this->elasticip = null;
}
public function testAllocateNewElasticIp()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "<AllocateAddressResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
. " <publicIp>67.202.55.255</publicIp>\r\n"
. "</AllocateAddressResponse>";
$this->adapter->setResponse($rawHttpResponse);
$ipAddress = $this->elasticip->allocate();
$this->assertEquals('67.202.55.255', $ipAddress);
}
public function testAssociateElasticIpWithInstanceReturnsTrue()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "<AssociateAddressResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
. " <return>true</return>\r\n"
. "</AssociateAddressResponse>";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->elasticip->associate('67.202.55.255', 'i-ag8ga0a');
$this->assertTrue($return);
}
/**
* Tests Zend_Service_Amazon_Ec2_Elasticip->describe()
*/
public function testDescribeSingleElasticIp()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "<DescribeAddressesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
. " <addressSet>\r\n"
. " <item>\r\n"
. " <publicIp>67.202.55.255</publicIp>\r\n"
. " <instanceId>i-ag8ga0a</instanceId>\r\n"
. " </item>\r\n"
. " </addressSet>\r\n"
. "</DescribeAddressesResponse>";
$this->adapter->setResponse($rawHttpResponse);
$response = $this->elasticip->describe('67.202.55.255');
$arrIp = array(
'publicIp' => '67.202.55.255',
'instanceId' => 'i-ag8ga0a'
);
$this->assertSame($arrIp, $response[0]);
}
public function testDescribeMultipleElasticIp()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "<DescribeAddressesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
. " <addressSet>\r\n"
. " <item>\r\n"
. " <publicIp>67.202.55.255</publicIp>\r\n"
. " <instanceId>i-ag8ga0a</instanceId>\r\n"
. " </item>\r\n"
. " <item>\r\n"
. " <publicIp>67.202.55.200</publicIp>\r\n"
. " <instanceId>i-aauoi9g</instanceId>\r\n"
. " </item>\r\n"
. " </addressSet>\r\n"
. "</DescribeAddressesResponse>";
$this->adapter->setResponse($rawHttpResponse);
$response = $this->elasticip->describe(array('67.202.55.255', '67.202.55.200'));
$arrIps = array(
array(
'publicIp' => '67.202.55.255',
'instanceId' => 'i-ag8ga0a'
),
array(
'publicIp' => '67.202.55.200',
'instanceId' => 'i-aauoi9g'
)
);
foreach($response as $k => $r) {
$this->assertSame($arrIps[$k], $r);
}
}
/**
* Tests Zend_Service_Amazon_Ec2_Elasticip->disassocate()
*/
public function testDisassocateElasticIpFromInstance()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "<DisassociateAddressResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
. " <return>true</return>\r\n"
. "</DisassociateAddressResponse>";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->elasticip->disassocate('67.202.55.255');
$this->assertTrue($return);
}
/**
* Tests Zend_Service_Amazon_Ec2_Elasticip->release()
*/
public function testReleaseElasticIp()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "<ReleaseAddressResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
. " <return>true</return>\r\n"
. "</ReleaseAddressResponse>";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->elasticip->release('67.202.55.255');
$this->assertTrue($return);
}
}