-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathCoreTest.php
More file actions
210 lines (170 loc) · 7.33 KB
/
CoreTest.php
File metadata and controls
210 lines (170 loc) · 7.33 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
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
<?php
namespace OpenStack\Integration\ObjectStore\v1;
use OpenStack\Integration\TestCase;
use OpenStack\Integration\Utils;
use Psr\Http\Message\StreamInterface;
class CoreTest extends TestCase
{
private $service;
/**
* @return \OpenStack\ObjectStore\v1\Service
*/
protected function getService()
{
if (null === $this->service) {
$this->service = Utils::getOpenStack()->objectStoreV1();
}
return $this->service;
}
public function runTests()
{
$this->startTimer();
$this->accountMetadata();
$this->containers();
$this->objects();
$this->outputTimeTaken();
}
public function accountMetadata()
{
$this->logStep('Ensure all metadata is wiped');
$this->getService()->getAccount()->resetMetadata([]);
$replacements = [
'{key_1}' => 'Foo',
'{key_2}' => 'Bar',
'{val_1}' => $this->randomStr(),
'{val_2}' => $this->randomStr(),
];
$this->logStep('Setting account metadata');
require_once $this->sampleFile($replacements, 'account/merge_metadata.php');
$this->logStep('Getting account metadata');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'account/get_metadata.php');
self::assertArraySubset([
'Foo' => $replacements['{val_1}'],
'Bar' => $replacements['{val_2}'],
], $metadata);
$this->logStep('Resetting account metadata');
$replacements = [
'{key_1}' => 'Foo1',
'{key_2}' => 'Bar1',
'{val_1}' => $this->randomStr(),
'{val_2}' => $this->randomStr(),
];
require_once $this->sampleFile($replacements, 'account/reset_metadata.php');
$this->logStep('Checking account metadata was reset properly');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'account/get_metadata.php');
self::assertEquals([
'Foo1' => $replacements['{val_1}'],
'Bar1' => $replacements['{val_2}'],
], $metadata);
}
public function containers()
{
$containerName = $this->randomStr();
$replacements = ['{containerName}' => $containerName];
$this->logStep('Create container');
require_once $this->sampleFile($replacements, 'containers/create.php');
$this->logStep('Get container');
require_once $this->sampleFile($replacements, 'containers/get.php');
$this->logStep('Listing containers');
require_once $this->sampleFile($replacements, 'containers/list.php');
$this->logStep('Merging metadata');
$replacements += [
'{key_1}' => 'Foo',
'{key_2}' => 'Bar',
'{val_1}' => $this->randomStr(),
'{val_2}' => $this->randomStr(),
];
require_once $this->sampleFile($replacements, 'containers/merge_metadata.php');
$this->logStep('Getting metadata');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'containers/get_metadata.php');
self::assertEquals([
'Foo' => $replacements['{val_1}'],
'Bar' => $replacements['{val_2}'],
], $metadata);
$this->logStep('Resetting metadata');
$replacements['{key_1}'] = 'Foo1';
$replacements['{key_2}'] = 'Bar1';
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'containers/reset_metadata.php');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'containers/get_metadata.php');
self::assertEquals([
'Foo1' => $replacements['{val_1}'],
'Bar1' => $replacements['{val_2}'],
], $metadata);
$this->logStep('Delete container');
$replacements = ['{containerName}' => $containerName];
require_once $this->sampleFile($replacements, 'containers/delete.php');
}
public function objects()
{
$containerName = $this->randomStr();
$this->logStep('Create container named {name}', ['{name}' => $containerName]);
$container = $this->getService()->createContainer(['name' => $containerName]);
$objectName = $this->randomStr();
$replacements = ['{containerName}' => $container->name, '{objectName}' => $objectName];
$this->logStep('Create object');
$replacements['{objectContent}'] = str_repeat('A', 1000);
require_once $this->sampleFile($replacements, 'objects/create.php');
$this->logStep('Copy object');
$newName = $this->randomStr();
$replacements += ['{newContainerName}' => $containerName, '{newObjectName}' => $newName];
require_once $this->sampleFile($replacements, 'objects/copy.php');
$this->logStep('Check that new object exists');
/** @var bool $exists */
require_once $this->sampleFile(['{containerName}' => $containerName, '{objectName}' => $newName], 'objects/check_exists.php');
self::assertTrue($exists);
$this->logStep('Downloading object');
/** @var StreamInterface $stream */
require_once $this->sampleFile($replacements, 'objects/download.php');
self::assertInstanceOf(StreamInterface::class, $stream);
self::assertEquals(1000, $stream->getSize());
$this->logStep('Downloading object using streaming');
/** @var StreamInterface $stream */
require_once $this->sampleFile($replacements, 'objects/download_stream.php');
self::assertInstanceOf(StreamInterface::class, $stream);
$body = '';
while (!$stream->eof()) {
$body .= $stream->read(64);
}
self::assertEquals(1000, strlen($body));
$this->logStep('Get object');
require_once $this->sampleFile($replacements, 'objects/get.php');
$this->logStep('Listing objects');
require_once $this->sampleFile($replacements, 'objects/list.php');
$this->logStep('Merging metadata');
$replacements += [
'{key_1}' => 'Foo',
'{key_2}' => 'Bar',
'{val_1}' => $this->randomStr(),
'{val_2}' => $this->randomStr(),
];
require_once $this->sampleFile($replacements, 'objects/merge_metadata.php');
$this->logStep('Getting metadata');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'objects/get_metadata.php');
self::assertEquals([
'Foo' => $replacements['{val_1}'],
'Bar' => $replacements['{val_2}'],
], $metadata);
$this->logStep('Resetting metadata');
$replacements['{key_1}'] = 'Foo1';
$replacements['{key_2}'] = 'Bar1';
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'objects/reset_metadata.php');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'objects/get_metadata.php');
self::assertEquals([
'Foo1' => $replacements['{val_1}'],
'Bar1' => $replacements['{val_2}'],
], $metadata);
$this->logStep('Delete object');
require_once $this->sampleFile($replacements, 'objects/delete.php');
$container->getObject($replacements['{newObjectName}'])->delete();
$this->logStep('Delete container');
$container->delete();
}
}