Skip to content

Commit

Permalink
Refactor tests (#384)
Browse files Browse the repository at this point in the history
use `include_once $this->sampleFile(` instead of `$path = $this->sampleFile(..); include_once $path`
  • Loading branch information
k0ka authored Jan 8, 2024
1 parent 2804874 commit 45bd478
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 346 deletions.
8 changes: 4 additions & 4 deletions src/Common/Resource/HasWaiterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ trait HasWaiterTrait
* will enter a loop, requesting feedback from the remote API until it sends back an appropriate
* status.
*
* @param string $status The state to be reached
* @param int $timeout The maximum timeout. If the total time taken by the waiter has reached
* or exceed this timeout, the blocking operation will immediately cease.
* @param int $sleepPeriod the amount of time to pause between each HTTP request
* @param string $status The state to be reached
* @param bool|int $timeout The maximum timeout. If the total time taken by the waiter has reached
* or exceed this timeout, the blocking operation will immediately cease.
* @param int $sleepPeriod the amount of time to pause between each HTTP request
*/
public function waitUntil(string $status, $timeout = 60, int $sleepPeriod = 1)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/BlockStorage/v2/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ protected function getService() : Service
return $this->service;
}

protected function sampleFile(array $replacements, $path)
protected function sampleFile($path, array $replacements = [])
{
return parent::sampleFile(
'../v3/' . $path,
array_merge(
$replacements,
['$openstack->blockStorageV3()' => '$openstack->blockStorageV2()']
),
'../v3/' . $path);
));
}
}
44 changes: 22 additions & 22 deletions tests/integration/BlockStorage/v3/CoreV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function volumes()

$this->logStep('Creating volume');
/** @var Volume $volume */
require_once $this->sampleFile($replacements, 'volumes/create.php');
require_once $this->sampleFile('volumes/create.php', $replacements);
self::assertInstanceOf(Volume::class, $volume);
self::assertEquals($replacements['{name}'], $volume->name);
self::assertEquals(1, $volume->size);
Expand All @@ -65,7 +65,7 @@ public function volumes()

$this->logStep('Getting volume');
/** @var Volume $volume */
require_once $this->sampleFile($replacements, 'volumes/get.php');
require_once $this->sampleFile('volumes/get.php', $replacements);
self::assertInstanceOf(Volume::class, $volume);

$replacements += [
Expand All @@ -75,18 +75,18 @@ public function volumes()

$this->logStep('Updating volume');
/** @var Volume $volume */
require_once $this->sampleFile($replacements, 'volumes/update.php');
require_once $this->sampleFile('volumes/update.php', $replacements);
self::assertInstanceOf(Volume::class, $volume);

$this->logStep('Listing volumes');
/** @var \Generator $volumes */
require_once $this->sampleFile($replacements, 'volumes/list.php');
require_once $this->sampleFile('volumes/list.php', $replacements);

$volume = $this->getService()->getVolume($volumeId);
$volume->waitUntil('available');

$this->logStep('Deleting volume');
require_once $this->sampleFile($replacements, 'volumes/delete.php');
require_once $this->sampleFile('volumes/delete.php', $replacements);

$volume = $this->getService()->getVolume($volumeId);
$volume->waitUntilDeleted();
Expand All @@ -103,30 +103,30 @@ public function volumeTypes()

$this->logStep('Creating volume type');
/** @var VolumeType $volumeType */
require_once $this->sampleFile($replacements, 'volume_types/create.php');
require_once $this->sampleFile('volume_types/create.php', $replacements);
self::assertInstanceOf(VolumeType::class, $volumeType);
self::assertEquals($replacements['{name}'], $volumeType->name);

$replacements = ['{volumeTypeId}' => $volumeType->id];

$this->logStep('Getting volume type');
/** @var VolumeType $volumeType */
require_once $this->sampleFile($replacements, 'volume_types/get.php');
require_once $this->sampleFile('volume_types/get.php', $replacements);
self::assertInstanceOf(VolumeType::class, $volumeType);

$replacements += ['{newName}' => $this->randomStr()];

$this->logStep('Updating volume type');
/** @var VolumeType $volumeType */
require_once $this->sampleFile($replacements, 'volume_types/update.php');
require_once $this->sampleFile('volume_types/update.php', $replacements);
self::assertInstanceOf(VolumeType::class, $volumeType);

$this->logStep('Listing volume types');
/** @var \Generator $volumeTypes */
require_once $this->sampleFile($replacements, 'volume_types/list.php');
require_once $this->sampleFile('volume_types/list.php', $replacements);

$this->logStep('Deleting volume type');
require_once $this->sampleFile($replacements, 'volume_types/delete.php');
require_once $this->sampleFile('volume_types/delete.php', $replacements);
}

public function snapshots()
Expand All @@ -143,7 +143,7 @@ public function snapshots()

$this->logStep('Creating snapshot');
/** @var Snapshot $snapshot */
require_once $this->sampleFile($replacements, 'snapshots/create.php');
require_once $this->sampleFile('snapshots/create.php', $replacements);
self::assertInstanceOf(Snapshot::class, $snapshot);
self::assertEquals($replacements['{name}'], $snapshot->name);
$volume->waitUntil('available', 60);
Expand All @@ -153,7 +153,7 @@ public function snapshots()

$this->logStep('Getting snapshot');
/** @var Snapshot $snapshot */
require_once $this->sampleFile($replacements, 'snapshots/get.php');
require_once $this->sampleFile('snapshots/get.php', $replacements);
self::assertInstanceOf(Snapshot::class, $snapshot);

$this->getService()
Expand All @@ -162,33 +162,33 @@ public function snapshots()

$replacements += ['{key}' => 'key2', '{val}' => 'val2'];
$this->logStep('Adding metadata');
require_once $this->sampleFile($replacements, 'snapshots/merge_metadata.php');
require_once $this->sampleFile('snapshots/merge_metadata.php', $replacements);

$this->logStep('Retrieving metadata');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'snapshots/get_metadata.php');
require_once $this->sampleFile('snapshots/get_metadata.php', $replacements);
self::assertEquals(['key1' => 'val1', 'key2' => 'val2'], $metadata);

$replacements = ['{snapshotId}' => $snapshot->id, '{key}' => 'key3', '{val}' => 'val3'];
$this->logStep('Resetting metadata');
require_once $this->sampleFile($replacements, 'snapshots/reset_metadata.php');
require_once $this->sampleFile('snapshots/reset_metadata.php', $replacements);

$this->logStep('Retrieving metadata');
/** @var array $metadata */
require_once $this->sampleFile($replacements, 'snapshots/get_metadata.php');
require_once $this->sampleFile('snapshots/get_metadata.php', $replacements);
self::assertEquals(['key3' => 'val3'], $metadata);

$replacements += ['{newName}' => $this->randomStr(), '{newDescription}' => $this->randomStr()];
$this->logStep('Updating snapshot');
require_once $this->sampleFile($replacements, 'snapshots/update.php');
require_once $this->sampleFile('snapshots/update.php', $replacements);

$snapshot->waitUntil('available', 60);

$this->logStep('Listing snapshots');
require_once $this->sampleFile($replacements, 'snapshots/list.php');
require_once $this->sampleFile('snapshots/list.php', $replacements);

$this->logStep('Deleting snapshot');
require_once $this->sampleFile($replacements, 'snapshots/delete.php');
require_once $this->sampleFile('snapshots/delete.php', $replacements);
$snapshot->waitUntilDeleted();

$this->logStep('Deleting volume');
Expand Down Expand Up @@ -223,18 +223,18 @@ public function snapshotList()
];

$this->logStep('Listing snapshots');
require_once $this->sampleFile($replacements, 'snapshots/list.php');
require_once $this->sampleFile('snapshots/list.php', $replacements);

$this->logStep('Listing snapshots sorted asc');
/** @var Snapshot $snapshot */
require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php');
require_once $this->sampleFile('snapshots/list_sorted.php', $replacements);
self::assertInstanceOf(Snapshot::class, $snapshot);
self::assertEquals($names[2], $snapshot->name);

$this->logStep('Listing snapshots sorted desc');
$replacements['{sortDir}'] = 'desc';
/** @var Snapshot $snapshot */
require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php');
require_once $this->sampleFile('snapshots/list_sorted.php', $replacements);
self::assertInstanceOf(Snapshot::class, $snapshot);
self::assertEquals($names[1], $snapshot->name);
} finally {
Expand Down
Loading

0 comments on commit 45bd478

Please sign in to comment.