-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for
format
parameter to specify the sql response form…
…at (#161) * feat: add test for SQL query endpoint Signed-off-by: Salih Candir <salih@live.at> * format on Sql cherry-pick from @archipelweb see: #156 Signed-off-by: archipelweb <github@archipel-web.com> * docs: add 'format' to allowed SQL query params Signed-off-by: Salih Candir <salih@live.at> * docs: update changelog Signed-off-by: Salih Candir <salih@live.at> * feat: make failed message of testFormatParamIsAllowedToSet more precise Signed-off-by: Salih Candir <salih@live.at> * refactor: add an line break at the end of line Signed-off-by: Salih Candir <salih@live.at> * docs: add example how to use query using sql Signed-off-by: Salih Candir <salih@live.at> --------- Signed-off-by: Salih Candir <salih@live.at> Signed-off-by: archipelweb <github@archipel-web.com> Co-authored-by: archipelweb <github@archipel-web.com>
- Loading branch information
1 parent
5c5453c
commit 9ebb183
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Elasticsearch PHP client | ||
* | ||
* @link https://github.com/elastic/elasticsearch-php/ | ||
* @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co) | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | ||
* @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1 | ||
* | ||
* Licensed to Elasticsearch B.V under one or more agreements. | ||
* Elasticsearch B.V licenses this file to you under the Apache 2.0 License or | ||
* the GNU Lesser General Public License, Version 2.1, at your option. | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
namespace OpenSearch\Tests\Endpoints; | ||
|
||
use OpenSearch\Common\Exceptions\UnexpectedValueException; | ||
use OpenSearch\Endpoints\Sql\Query; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \OpenSearch\Endpoints\Sql\Query | ||
*/ | ||
class SqlQueryEndpointTest extends TestCase | ||
{ | ||
/** | ||
* @var Query | ||
*/ | ||
private $endpoint; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->endpoint = new Query(); | ||
} | ||
|
||
public function testFormatIsInParamWhitelist(): void | ||
{ | ||
$this->assertContains('format', $this->endpoint->getParamWhitelist()); | ||
} | ||
|
||
public function testMethodIsPost(): void | ||
{ | ||
$this->assertSame('POST', $this->endpoint->getMethod()); | ||
} | ||
|
||
public function testUriIsSqlPlugin(): void | ||
{ | ||
$this->assertSame('/_plugins/_sql', $this->endpoint->getURI()); | ||
} | ||
|
||
public function testFormatParamIsAllowedToSet(): void | ||
{ | ||
try { | ||
$this->endpoint->setParams([ | ||
'format' => 'json', | ||
]); | ||
} catch (UnexpectedValueException $e) { | ||
$this->fail('The format param should be allowed to set but it was not. Format is may not whitelisted.'); | ||
} | ||
} | ||
|
||
public function testFormatParamIsJson(): void | ||
{ | ||
$this->endpoint->setParams([ | ||
'format' => 'json', | ||
]); | ||
|
||
$params = $this->endpoint->getParams(); | ||
$this->assertSame('json', $params['format']); | ||
} | ||
} |