Skip to content

Commit

Permalink
Fix TarantoolVersionRequirement to support the new versioning scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
rybakit committed Apr 28, 2022
1 parent 4830cf8 commit 3f2c3c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/Annotation/Requirement/TarantoolVersionRequirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getName() : string

public function check(string $value) : ?string
{
// replace dash with dot
// Replace dash with dot.
$constraints = preg_replace('/(\d+\.\d+\.\d+)-(\d+)/', '$1.$2', $value);

if (Semver::satisfies($this->getVersion(), $constraints)) {
Expand All @@ -53,9 +53,14 @@ private function getVersion() : string
}

$version = $this->client->call('box.info')[0]['version'];
// normalize 2.2.1-3-g878e2a42c to 2.2.1.3

// Normalize 2.2.1-3-g878e2a42c to 2.2.1.3.
$version = preg_replace('/-(\d+)-[^-]+$/', '.$1', $version);

// Treat "entrypoint" versions as "dev",
// so 2.11.0-entrypoint.8 becomes 2.11.0-dev+entrypoint.8.
$version = preg_replace('/(\d)-entrypoint/', '$1-dev+entrypoint', $version);

return $this->version = $version;
}
}
11 changes: 10 additions & 1 deletion tests/Annotation/Requirement/TarantoolVersionRequirementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public function provideCheckPassesForValidConstraintsData() : iterable
[$v2_3_1_3, '< 2.3.2'],
[$v2_3_1_3, '< 2.4'],
[$v2_3_1_3, '< 3'],

// @see https://github.com/tarantool/tarantool/discussions/6182
['2.11.0-entrypoint', '< 2.11.0-alpha'],
['2.11.0-entrypoint.8', '< 2.11.0-alpha'],
['2.11.0-entrypoint.8', '< 2.11.1'],
['2.11.0-entrypoint', '= 2.11.0-dev'],
['2.11.0-entrypoint.8', '= 2.11.0-dev'],
['2.11.0-entrypoint.8-g878e2a42c', '= 2.11.0-dev'],
['2.11.0-entrypoint-17-g878e2a42c-dev', '= 2.11.0-dev'],
];
}

Expand All @@ -93,7 +102,7 @@ public function testCheckFailsForInvalidConstraints(string $serverVersion, strin
{
$mockClient = $this->getTestDoubleClientBuilder()
->shouldHandle(
new CallRequest('box.info'), // $this->logicalOr()
new CallRequest('box.info'),
TestDoubleFactory::createResponseFromData([['version' => $serverVersion]]))
->build();

Expand Down

0 comments on commit 3f2c3c5

Please sign in to comment.