diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 6f615d3e..11f396c4 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -36,6 +36,14 @@ The integration tests are using by default following address `https://admin:admi To run the integration tests, you can use `composer run integration` +```bash +export OPENSEARCH_PASSWORD=myStrongPassword123! +export OPENSEARCH_URL=https://admin:$OPENSEARCH_PASSWORD@localhost:9200 + +composer run integration +``` + + ### Static analyse and code style checker The project uses PhpStan for static analyse and php-cs-fixer for code style checker. You can use both tools with following codes diff --git a/tests/Endpoints/MlNamespaceIntegrationTest.php b/tests/Endpoints/MlNamespaceIntegrationTest.php index 61962d88..6c10335a 100644 --- a/tests/Endpoints/MlNamespaceIntegrationTest.php +++ b/tests/Endpoints/MlNamespaceIntegrationTest.php @@ -30,7 +30,7 @@ public function testRegisterModelGroup() { $client = Utility::getClient(); - if (!Utility::isOpenSearchVersionAtLeast($client, '2.8.0') || !Utility::isOpenSearchVersionAtmost($client, '2.x')) { + if (!Utility::isOpenSearchVersionAtLeast($client, '2.8.0')) { $this->markTestSkipped('Ml plugin tests require OpenSearch >= 2.8.0'); } @@ -47,7 +47,7 @@ public function testgetModels() { $client = Utility::getClient(); - if (!Utility::isOpenSearchVersionAtLeast($client, '2.12.0') || !Utility::isOpenSearchVersionAtmost($client, '2.x')) { + if (!Utility::isOpenSearchVersionAtLeast($client, '2.12.0')) { $this->markTestSkipped('Ml plugin tests require OpenSearch >= 2.12.0'); } @@ -59,7 +59,7 @@ public function testsearchModels() { $client = Utility::getClient(); - if (!Utility::isOpenSearchVersionAtLeast($client, '2.12.0') || !Utility::isOpenSearchVersionAtmost($client, '2.x')) { + if (!Utility::isOpenSearchVersionAtLeast($client, '2.12.0')) { $this->markTestSkipped('Ml plugin tests require OpenSearch >= 2.12.0'); } diff --git a/tests/Utility.php b/tests/Utility.php index 8775829a..7ca46e2d 100644 --- a/tests/Utility.php +++ b/tests/Utility.php @@ -79,35 +79,7 @@ public static function isOpenSearchVersionAtLeast(Client $client, string $versio return false; } $versionNumber = $versionInfo['number']; - return version_compare($versionNumber, $version) >= 0; - } - - /** - * Check if cluster is OpenSearch and version is less than the specified version. - */ - public static function isOpenSearchVersionAtMost(Client $client, string $version): bool - { - $versionInfo = self::getVersion($client); - $distribution = $versionInfo['distribution'] ?? null; - if ($distribution !== 'opensearch') { - return false; - } - $versionNumber = $versionInfo['number']; - return version_compare($versionNumber, $version, '<'); - } - - /** - * Check if cluster is Elasticsearch and version is greater than or equal to specified version. - */ - public static function isElasticSearchVersionAtLeast(Client $client, string $version): bool - { - $versionInfo = self::getVersion($client); - $distribution = $versionInfo['distribution'] ?? null; - if ($distribution === 'opensearch') { - return false; - } - $versionNumber = $versionInfo['number']; - return version_compare($versionNumber, $version) >= 0; + return version_compare($versionNumber, $version, '>='); } private static function getVersion(Client $client): array @@ -137,10 +109,7 @@ public static function cleanUpCluster(Client $client): void */ private static function wipeCluster(Client $client): void { - if (self::isElasticSearchVersionAtLeast($client, '7.4.0')) { - self::deleteAllSLMPolicies($client); - } - + self::deleteAllSLMPolicies($client); self::wipeSnapshots($client); self::wipeDataStreams($client); self::wipeAllIndices($client); @@ -229,12 +198,10 @@ private static function deleteAllSLMPolicies(Client $client): void private static function wipeDataStreams(Client $client): void { try { - if (self::isElasticSearchVersionAtLeast($client, '7.9.0')) { - $client->indices()->deleteDataStream([ - 'name' => '*', - 'expand_wildcards' => 'all' - ]); - } + $client->indices()->deleteDataStream([ + 'name' => '*', + 'expand_wildcards' => 'all' + ]); } catch (OpenSearchException $e) { // We hit a version of ES that doesn't understand expand_wildcards, try again without it try { @@ -255,14 +222,10 @@ private static function wipeDataStreams(Client $client): void */ private static function wipeAllIndices(Client $client): void { - $expand = 'open,closed'; - if (self::isElasticSearchVersionAtLeast($client, '7.7.0')) { - $expand .= ',hidden'; - } try { $client->indices()->delete([ 'index' => '*,-.ds-ilm-history-*', - 'expand_wildcards' => $expand + 'expand_wildcards' => 'open,closed,hidden' ]); } catch (Exception $e) { if ($e->getCode() != '404') {